sequences.extras: adding cut-when.

db4
John Benediktsson 2013-09-05 20:58:36 -07:00
parent f1b1598885
commit 430e73b16c
2 changed files with 9 additions and 0 deletions

View File

@ -164,3 +164,8 @@ IN: sequences.extras.tests
{ "ab" } [ f 2 "abcdef" subseq* ] unit-test
{ "cdef" } [ 2 f "abcdef" subseq* ] unit-test
{ "cd" } [ -4 -2 "abcdef" subseq* ] unit-test
{ "foo" "" } [ "foo" [ blank? ] cut-when ] unit-test
{ "foo" " " } [ "foo " [ blank? ] cut-when ] unit-test
{ "" " foo" } [ " foo" [ blank? ] cut-when ] unit-test
{ "foo" " bar" } [ "foo bar" [ blank? ] cut-when ] unit-test

View File

@ -482,3 +482,7 @@ PRIVATE>
{ 3 [ first3-unsafe f ] }
[ drop first4-unsafe ]
} case ;
: cut-when ( ... seq quot: ( ... elt -- ... ? ) -- ... before after )
[ find drop ] 2keep drop swap
[ cut ] [ f over like ] if* ; inline