sequences.extras: fix bug in count-head, add some tests.

elevate-erg
John Benediktsson 2018-07-06 08:07:11 -07:00
parent 739742d0ae
commit 6e89e4ecab
2 changed files with 9 additions and 1 deletions

View File

@ -273,3 +273,11 @@ tools.test vectors vocabs ;
{ "a_b" } [ "ab" CHAR: _ interleaved ] unit-test
{ "a_b_c" } [ "abc" CHAR: _ interleaved ] unit-test
{ "a_b_c_d" } [ "abcd" CHAR: _ interleaved ] unit-test
{ 0 } [ { 1 2 3 4 } [ 5 > ] count-head ] unit-test
{ 2 } [ { 1 2 3 4 } [ 3 < ] count-head ] unit-test
{ 4 } [ { 1 2 3 4 } [ 5 < ] count-head ] unit-test
{ 0 } [ { 1 2 3 4 } [ 5 > ] count-tail ] unit-test
{ 2 } [ { 1 2 3 4 } [ 2 > ] count-tail ] unit-test
{ 4 } [ { 1 2 3 4 } [ 5 < ] count-tail ] unit-test

View File

@ -629,7 +629,7 @@ PRIVATE>
[ dup length ] unless* tail-slice ; inline
: count-head ( seq quot -- n )
[ not ] compose find drop ; inline
[ not ] compose [ find drop ] 2keep drop length or ; inline
: count-tail ( seq quot -- n )
[ not ] compose [ find-last drop ] 2keep drop