]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: add map-zip.
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 29 Mar 2016 19:58:26 +0000 (12:58 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 29 Mar 2016 19:58:26 +0000 (12:58 -0700)
extra/sequences/extras/extras-tests.factor
extra/sequences/extras/extras.factor

index b4c8038f24894a9f331b215248bda6be072c9c6c..838259fe9ada5bf07003a583ba37bc966430b0b9 100644 (file)
@@ -1,7 +1,6 @@
-USING: arrays ascii io io.streams.string kernel make math
-math.vectors random sequences sequences.extras strings
-tools.test vectors ;
-
+USING: accessors arrays ascii io io.streams.string kernel make
+math math.vectors random sequences sequences.extras strings
+tools.test vectors vocabs ;
 IN: sequences.extras.tests
 
 { { "a" "b" "c" "d" "ab" "bc" "cd" "abc" "bcd" "abcd" } } [ "abcd" all-subseqs ] unit-test
@@ -183,3 +182,15 @@ IN: sequences.extras.tests
 { 2 } [ "ABA" "ABABA" count-subseq* ] unit-test
 
 { 120000 } [ { 10 20 30 40 50 60 } 1 [ * ] 3 reduce-from ] unit-test
+
+{
+    {
+        { 2 4 }
+        { 3 6 }
+        { 4 8 }
+    }
+} [ { 2 3 4 } [ 2 * ] map-zip ] unit-test
+
+{ }
+[ "test:" all-words [ name>> over prepend ] map-zip 2drop ] unit-test
+
index eabf091b7336250040fda942d256d8abae52f3c9..d562d82e1b40799c76a1c1f2566ab66d99f721dc 100644 (file)
@@ -551,3 +551,6 @@ PRIVATE>
 
 : count-subseq* ( subseq seq -- n )
     start-all* length ; inline
+
+: map-zip ( quot: ( x -- y ) -- alist )
+    '[ [ _ call ] [ ] bi swap ] map>alist ; inline
\ No newline at end of file