Provide a sequence function called "last"

21 views
Skip to first unread message

pcxunl...@gmail.com

unread,
Aug 22, 2014, 3:07:58 PM8/22/14
to strati...@googlegroups.com
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

unread,
Aug 24, 2014, 9:39:57 PM8/24/14
to strati...@googlegroups.com, pcxunl...@gmail.com

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?

Cheers,
 - Tim.

pcxunl...@gmail.com

unread,
Aug 24, 2014, 10:54:59 PM8/24/14
to strati...@googlegroups.com, pcxunl...@gmail.com
Thanks! You guys are awesome.

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

pcxunl...@gmail.com

unread,
Aug 24, 2014, 11:29:17 PM8/24/14
to strati...@googlegroups.com, pcxunl...@gmail.com
Hmm... I grepped around and couldn't find it.

I did, however, find this: https://conductance.io/examples/snapshots/ (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
Forward
0 new messages