sequences.extras: simpler find-all and a test.

char-rename
John Benediktsson 2016-12-29 09:20:32 -08:00
parent f0251cb2ad
commit a153d9f6ad
2 changed files with 4 additions and 4 deletions

View File

@ -3,6 +3,8 @@ math math.vectors random sequences sequences.extras strings
tools.test vectors vocabs ;
IN: sequences.extras.tests
{ { { 0 104 } { 2 108 } { 3 108 } } } [ "hello" [ even? ] find-all ] unit-test
{ { "a" "b" "c" "d" "ab" "bc" "cd" "abc" "bcd" "abcd" } } [ "abcd" all-subseqs ] unit-test
{ { "a" "ab" "abc" "abcd" "b" "bc" "bcd" "c" "cd" "d" } }

View File

@ -21,10 +21,8 @@ IN: sequences.extras
:: combos ( list1 list2 -- result )
list2 [ [ 2array ] curry list1 swap map ] map concat ;
: find-all ( seq quot: ( elt -- ? ) -- elts )
[ [ length iota ] keep ] dip
[ dupd call( a -- ? ) [ 2array ] [ 2drop f ] if ] curry
2map sift ; inline
: find-all ( ... seq quot: ( ... elt -- ... ? ) -- ... elts )
[ <enum> ] dip '[ nip @ ] assoc-filter ; inline
: reduce-from ( ... seq identity quot: ( ... prev elt -- ... next ) i -- ... result )
[ swap ] 2dip each-from ; inline