sequences.extras: additional tests for take-while and drop-while.

char-rename
John Benediktsson 2017-01-26 22:09:13 -08:00
parent e462f85c66
commit 369f5b6d13
2 changed files with 6 additions and 2 deletions

View File

@ -247,6 +247,8 @@ IN: sequences.extras.tests
{ { 0 1 2 3 } } [ 8 iota [ 4 < ] take-while >array ] unit-test
{ { } } [ { 15 16 } [ 4 < ] take-while >array ] unit-test
{ { 0 1 2 } } [ 3 iota [ 4 < ] take-while >array ] unit-test
{ { 4 5 6 7 } } [ 8 iota [ 4 < ] drop-while >array ] unit-test
{ { 15 16 } } [ { 15 16 } [ 4 < ] drop-while >array ] unit-test
{ { } } [ 3 iota [ 4 < ] drop-while >array ] unit-test

View File

@ -604,7 +604,9 @@ PRIVATE>
'[ swap _ dip swap ] assoc-map ; inline
: take-while ( ... seq quot: ( ... elt -- ... ? ) -- head-slice )
[ '[ @ not ] find drop ] 2keep drop swap 0 or head-slice ; inline
[ '[ @ not ] find drop ] 2keep drop swap
[ dup length ] unless* head-slice ; inline
: drop-while ( ... seq quot: ( ... elt -- ... ? ) -- tail-slice )
[ '[ @ not ] find drop ] 2keep drop swap 0 or tail-slice ; inline
[ '[ @ not ] find drop ] 2keep drop swap
[ dup length ] unless* tail-slice ; inline