]> gitweb.factorcode.org Git - factor.git/commitdiff
math.combinatorics: produce type of sequence in selections.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 6 Apr 2013 20:06:23 +0000 (13:06 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 6 Apr 2013 20:06:23 +0000 (13:06 -0700)
basis/math/combinatorics/combinatorics-tests.factor
basis/math/combinatorics/combinatorics.factor

index 5ae2ceffc0bdbe26ea9a703a383ba2952cd7f3c4..89809f2d3e2376e18ef2298048ca4ba2796e8fa0 100644 (file)
@@ -79,6 +79,8 @@ IN: math.combinatorics.tests
     { 2 1 1 } { 2 1 2 } { 2 2 1 } { 2 2 2 } } ]
 [ { 1 2 } 3 selections ] unit-test
 
+{ { "aa" "ab" "ac" "ba" "bb" "bc" "ca" "cb" "cc" } }
+[ "abc" 2 selections ] unit-test
 
 { V{ { 1 2 } { 1 3 } } }
 [ { 1 2 3 } 2 [ { 1 } head? ] filter-combinations ] unit-test
index c9109eb63df81bfef9f8dbed302b0cf68b019b9c..69f2f2aca5ceb8cdef1ef287c49283ce55eeda29 100644 (file)
@@ -189,8 +189,8 @@ INSTANCE: combinations immutable-sequence
 <PRIVATE
 
 : (selections) ( seq n -- selections )
-    [ [ 1array ] map dup ] [ 1 - ] bi* [
-        cartesian-product concat [ { } concat-as ] map
+    [ dup [ 1sequence ] curry { } map-as dup ] [ 1 - ] bi* [
+        cartesian-product concat [ concat ] map
     ] with times ;
 
 PRIVATE>