]> gitweb.factorcode.org Git - factor.git/commitdiff
Move partition combinator into core
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 6 Sep 2008 00:32:19 +0000 (19:32 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 6 Sep 2008 00:32:19 +0000 (19:32 -0500)
core/sequences/sequences-tests.factor
core/sequences/sequences.factor
extra/sequences/lib/lib.factor

index fa5a3aecfbb0c37ab0edf7e579199360d306f7c1..8d7a0469a09f132db2de8cc24c139cf2705497a8 100755 (executable)
@@ -260,3 +260,9 @@ TUPLE: bogus-hashcode ;
 M: bogus-hashcode hashcode* 2drop 0 >bignum ;
 
 [ 0 ] [ { T{ bogus-hashcode } } hashcode ] unit-test
+
+[ { 2 4 6 } { 1 3 5 7 } ] [ { 1 2 3 4 5 6 7 } [ even? ] partition ] unit-test
+
+[ { 1 3 7 } ] [ 2 { 1 3 5 7 } remove-nth ] unit-test
+
+[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ] unit-test
index c70d15701e6080a95cbfa78c5bcf8afd0e0fbe59..2ce939d96f29e3a6eb6f74ea5afc68fc02465e86 100755 (executable)
@@ -426,6 +426,15 @@ PRIVATE>
 : filter ( seq quot -- subseq )
     over >r pusher >r each r> r> like ; inline
 
+: push-either ( elt quot accum1 accum2 -- )
+    >r >r keep swap r> r> ? push ; inline
+
+: 2pusher ( quot -- quot accum1 accum2 )
+    V{ } clone V{ } clone [ [ push-either ] 3curry ] 2keep ; inline
+
+: partition ( seq quot -- trueseq falseseq )
+    over >r 2pusher >r >r each r> r> r> tuck [ like ] 2bi@ ; inline
+
 : monotonic? ( seq quot -- ? )
     >r dup length 1- swap r> (monotonic) all? ; inline
 
index a09b3d5b829862fc235555d8f8d7c7c3c34eac51..2eb3c44b421755f7380b9fc21beec35525011f6b 100755 (executable)
@@ -135,15 +135,6 @@ PRIVATE>
 : power-set ( seq -- subsets )
     2 over length exact-number-strings swap [ switches ] curry map ;
 
-: push-either ( elt quot accum1 accum2 -- )
-    >r >r keep swap r> r> ? push ; inline
-
-: 2pusher ( quot -- quot accum1 accum2 )
-    V{ } clone V{ } clone [ [ push-either ] 3curry ] 2keep ; inline
-
-: partition ( seq quot -- trueseq falseseq )
-    over >r 2pusher >r >r each r> r> r> drop ; inline
-
 : cut-find ( seq pred -- before after )
     dupd find drop dup [ cut ] when ;