sequences.extras: Add first=, first?, etc
parent
3014b1828a
commit
1bd36d5991
|
@ -123,3 +123,17 @@ IN: sequences.extras.tests
|
|||
|
||||
{ 1 } [ { 1 7 3 7 6 3 7 } arg-max ] unit-test
|
||||
{ 0 } [ { 1 7 3 7 6 3 7 } arg-min ] unit-test
|
||||
|
||||
{ t } [ { 1 2 3 4 5 } 1 first= ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } 2 second= ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } 3 third= ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } 4 fourth= ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } 5 last= ] unit-test
|
||||
{ t } [ 4 { 1 2 3 4 5 } 5 nth= ] unit-test
|
||||
|
||||
{ t } [ { 1 2 3 4 5 } [ 1 = ] first? ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } [ 2 = ] second? ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } [ 3 = ] third? ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } [ 4 = ] fourth? ] unit-test
|
||||
{ t } [ { 1 2 3 4 5 } [ 5 = ] last? ] unit-test
|
||||
{ t } [ 4 { 1 2 3 4 5 } [ 5 = ] nth? ] unit-test
|
||||
|
|
|
@ -294,3 +294,17 @@ INSTANCE: odds immutable-sequence
|
|||
: arg-where ( ... seq quot: ( ... elt -- ... ? ) -- ... indices )
|
||||
[ dup length iota zip ] dip
|
||||
[ first-unsafe ] prepose filter values ; inline
|
||||
|
||||
: first= ( seq elt -- ? ) [ first ] dip = ; inline
|
||||
: second= ( seq elt -- ? ) [ second ] dip = ; inline
|
||||
: third= ( seq elt -- ? ) [ third ] dip = ; inline
|
||||
: fourth= ( seq elt -- ? ) [ fourth ] dip = ; inline
|
||||
: last= ( seq elt -- ? ) [ last ] dip = ; inline
|
||||
: nth= ( n seq elt -- ? ) [ nth ] dip = ; inline
|
||||
|
||||
: first? ( seq quot -- ? ) [ first ] dip call ; inline
|
||||
: second? ( seq quot -- ? ) [ second ] dip call ; inline
|
||||
: third? ( seq quot -- ? ) [ third ] dip call ; inline
|
||||
: fourth? ( seq quot -- ? ) [ fourth ] dip call ; inline
|
||||
: last? ( seq quot -- ? ) [ last ] dip call ; inline
|
||||
: nth? ( n seq quot -- ? ) [ nth ] dip call ; inline
|
||||
|
|
Loading…
Reference in New Issue