Provide a sequence function called "last"

Skip to first unread message

Aug 22, 2014, 3:07:58 PM8/22/14
There's currently a sequence function called "first", I propose to add in a new sequence function called "last".

The code foo[foo.length - 1] is quite common. Being able to use @last(foo) instead would be much nicer. Using @at(foo, -1) also works, but your intention is much clearer by using "last".

The "last" function could simply be a short alias for at(foo, -1)

    function last(sequence) {
      return at(sequence, -1);

If you wanted to, you could add in an optimization for arrays, so it would be equivalent to foo[foo.length - 1], but I don't think that's necessary if the "at" function is fast enough.

I would also recommend updating the documentation to replace uses of foo[foo.length - 1] with last(foo), but that is lower priority and doesn't need to be done right away.

Tim Cuthbertson

Aug 24, 2014, 9:39:57 PM8/24/14

Good suggestion, added :)

I didn't notice any uses of `length - 1` in the documentation - did you see any specifically, or was that just a general suggestion?

 - Tim.

Aug 24, 2014, 10:54:59 PM8/24/14
Thanks! You guys are awesome.

I do actually remember seeing at least one, but I'll have to go and find it.

Aug 24, 2014, 11:29:17 PM8/24/14
Hmm... I grepped around and couldn't find it.

I did, however, find this: (try searching for imgs.length)

I don't think it's a big deal, you can just fix them as you come across them.
Reply all
Reply to author
0 new messages