collections: add cut word

locals-and-roots
Doug Coleman 2016-06-27 11:30:44 -07:00
parent 19510ea5a7
commit 0e6fd48c11
2 changed files with 15 additions and 4 deletions

View File

@ -256,4 +256,7 @@ IN: sequences.extras.tests
[ undefined-find-nth? ] must-fail-with
{ { 1 1 2 1 } }
[ 3 { 1 1 2 1 } [ 2 = not ] head-nth ] unit-test
[ 3 { 1 1 2 1 1 1 } [ 2 = not ] head-nth-match ] unit-test
{ { 1 1 2 1 } { 1 1 } }
[ 3 { 1 1 2 1 1 1 } [ 2 = not ] cut-nth-match ] unit-test

View File

@ -627,12 +627,20 @@ ERROR: undefined-find-nth m n seq quot ;
: find-last-nth ( n seq quot -- i/f elt/f )
[ [ nip length 1 - ] [ ] 2bi ] dip find-last-nth-from ; inline
ERROR: head-nth-reached-end n seq quot ;
:: head-nth ( n seq quot -- seq' )
ERROR: combinator-nth-reached-end n seq quot ;
:: head-nth-match ( n seq quot -- seq' )
n seq quot find-nth drop [
[ seq ] dip 1 + head
] [
n seq quot head-nth-reached-end
n seq quot combinator-nth-reached-end
] if* ; inline
:: cut-nth-match ( n seq quot -- seq' )
n seq quot find-nth drop [
[ seq ] dip 1 + head
] [
n seq quot combinator-nth-reached-end
] if* ; inline
:: (start-all) ( subseq seq increment -- indices )