]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: simpler find-all and a test.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 29 Dec 2016 17:20:32 +0000 (09:20 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 29 Dec 2016 17:20:32 +0000 (09:20 -0800)
extra/sequences/extras/extras-tests.factor
extra/sequences/extras/extras.factor

index eef8d01888e85bac47dd6c0d8fad9e5ac70d16c9..6e906dec21b426b21bdd36a9c6f18c4f58936e79 100644 (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" } }
index cc459ebead037ee47dd03a58918b5c1daca54e9a..aa901bd808d1dba90aaf10c8b0a7c428f1edc9fe 100644 (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