]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: change implementation of interleave
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 14 Jun 2009 23:22:31 +0000 (18:22 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 14 Jun 2009 23:22:31 +0000 (18:22 -0500)
core/sequences/sequences.factor

index 745fe2a0330baaa35f645659900d10d5db4b73f6..c58304de44bc97989b7a8e86c36b9c12cbadd1f2 100755 (executable)
@@ -508,9 +508,11 @@ PRIVATE>
     (each-index) each-integer ; inline
 
 : interleave ( seq between quot -- )
-    swap [ drop ] [ [ 2dip call ] 2curry ] 2bi
-    [ [ 0 = ] 2dip if ] 2curry
-    each-index ; inline
+    pick empty? [ 3drop ] [
+        [ [ drop first-unsafe ] dip call ]
+        [ [ rest-slice ] 2dip [ [ call ] bi@ ] 2curry each ]
+        3bi
+    ] if ; inline
 
 : map-index ( seq quot -- newseq )
     [ dup length iota ] dip 2map ; inline