sequences.extras: adding nth* which is nth from the end.

db4
John Benediktsson 2013-09-12 12:47:04 -07:00
parent 0fcb485d80
commit 454bffc14e
2 changed files with 5 additions and 0 deletions

View File

@ -169,3 +169,5 @@ IN: sequences.extras.tests
{ "foo" " " } [ "foo " [ blank? ] cut-when ] unit-test
{ "" " foo" } [ " foo" [ blank? ] cut-when ] unit-test
{ "foo" " bar" } [ "foo bar" [ blank? ] cut-when ] unit-test
{ { 4 0 3 1 2 } } [ { 0 4 1 3 2 } 5 iota [ nth* ] curry map ] unit-test

View File

@ -486,3 +486,6 @@ PRIVATE>
: cut-when ( ... seq quot: ( ... elt -- ... ? ) -- ... before after )
[ find drop ] 2keep drop swap
[ cut ] [ f over like ] if* ; inline
: nth* ( n seq -- elt )
[ length 1 - swap - ] [ nth ] bi ; inline