sequences.extras: adding "none?" and "one?".

db4
John Benediktsson 2012-08-06 08:52:45 -07:00
parent 316fdf0461
commit 04794fe715
2 changed files with 16 additions and 0 deletions

View File

@ -100,3 +100,11 @@ IN: sequences.extras.tests
{ "" } [ "" "" "" unsurround ] unit-test
{ "" } [ " " " " " " unsurround ] unit-test
{ "foo.com" } [ "http://foo.com" "http://" "/" unsurround ] unit-test
{ t } [ { 1 3 5 7 } [ even? ] none? ] unit-test
{ f } [ { 1 2 3 4 } [ even? ] none? ] unit-test
{ t } [ { } [ even? ] none? ] unit-test
{ f } [ { 1 2 3 4 } [ even? ] one? ] unit-test
{ t } [ { 1 2 3 } [ even? ] one? ] unit-test
{ f } [ { } [ even? ] one? ] unit-test

View File

@ -216,3 +216,11 @@ PRIVATE>
: unsurround ( newseq seq2 seq3 -- seq1 )
[ ?head drop ] [ ?tail drop ] bi* ;
: none? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
any? not ; inline
: one? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
[ find ] 2keep rot [
[ 1 + ] 2dip find-from drop not
] [ 3drop f ] if ; inline