List(1,2,3).Splice(0, 0, List(4)) should return List(1,2,3,4)

Right now

List(1,2,3).Splice(0, 0, List(4))


List(1,2,3).Splice(1, 0, List(4))

also returns List(4,1,2,3).

This is a huge bummer for the times when we would like to truly append an item to the end of the list.

How can I get List(1,2,3,4)? Well, the best I can do is:

WithName(List(1,2,3), MyList, MyList.Splice(MyList.Count()+1, 0, List(4)))

If I were to come across this formula in a doc I would be quite confused as to what it was doing. It seems unnecessarily verbose considering what it’s doing is basically List(1,2,3).Append(List(4)).

Since MyList.Splice(0,0, whatever) returns the same thing as MyList.Splice(1, 0, whatever) it would be nice to use 0 as append and 1 as prepend.

Loose EndsWhat happens when the delete argument is non-zero? Like `Splice(0, 2, whatever)`? Nothing. You heard me. Nothing happens!

I think you have this technically wrong since the first field is the value. Ultimately what you are asking for, is that for the start field, 0 acts as end of list? Its not exactly intuitive but would be very handy!

Try it!

List(1,2,3).Splice(0, 0, List(4))


List(1,2,3).Splice(1, 0, List(4))

are identical!

Edit: ah I see you’re saying that the first argument of Splice is the list to operate on. Right yeah, I guess I left that implicit. I’ll edit!

Yep. Somewhat agreed, although this is what happens when you don’t use 0 indexing, some things become less intuitive (and other things become more intuitive)

1 Like

Agreed - I’m trying to create a list of lists using a formula map and I’m having to use withName/splice because (a) there’s no append method, and (b) listcombine deep-flattens which isn’t what I want.

That said, I don’t know that the solution is to have 0 add to end of list. Personally, I think it should support negative integers and have -1 be the last position in line with the 1 indexing. That way you have both a simple append and a more sophisticated ability to add to reverse positions.

I think it does support negative indexing, right?

You’re right - it does, but for some reason negative indexing is 0 indexed, not 1 indexed, so you can’t append to the end (unless I’m mistaken) without doing something wonky like having an empty value at the end of the list on purpose.

I understand what you mean. start 1 and 0 both insert in the beginning, and -1 inserts one item before the end. The only way to append an item with Splice is to specify initial list’s Count()… or give it an arbitrary large value, lol


I personally use ListCombine() when I want to append stuff. I’d say this is a bug… but at the same time I’m not sure that 0 should mean “append to the end” because it’s counterlogical. Yeah, Coda indices are 1-based, but 0 means append would then be a special case that’s even more confusing.

Ah, yeah I see your point @Christian_Rodriguez3

Splice(0, 0, “thing”) should add thing in the first position.

Splice(-1, 0, “thing”) should append

This is a place where 0 indexing is very pretty.

Doesn’t work when you’re appending a list to a list of lists, unfortunately. It flattens the entire thing. But the arbitrarily large number method works, I guess haha

Even if one-indexed, it should be one-indexed in both directions. Currently it’s one-indexed for LTR but zero-indexed (ish) for RTL.

It should currently be:
Splice(1, 0, “thing”) should add to first position
Splice(-1, 0, “thing”) should append

Yeah I think it’s a bug. I’m going to recategorize this post

Added it here: Splice(-1, 0, “thing”) should append

@Christian_Rodriguez3 I will say, the issue with this rule is that deleting the last element is much less elegant. To delete the last element, you’d have to write MyList.Splice(-2, 1) the -2 seems a bit weird considering you’re only deleting 1 element. At least with MyList.Splice(0, 0, "thing") as append, you could keep MyList.Splice(-1, 1) as deleting the final element, which is a very intuitive syntax