]> gitweb.factorcode.org Git - factor.git/blobdiff - core/sequences/sequences.factor
sequences: count is [ ] count-by, readd seq-copy-loop again
[factor.git] / core / sequences / sequences.factor
index 7db35f65f9e9538efeede1aa71c99edf37d56a8e..4d5bc5219e77095ff603a1ba15a1dab95d796947 100644 (file)
@@ -364,6 +364,16 @@ C: <copier> copier
 : subseq-unsafe ( from to seq -- subseq )
     dup subseq-unsafe-as ; inline
 
+: seq-copy-loop ( dst dst-i src src-i src-stop -- dst )
+    2dup >= [
+        4drop
+    ] [
+        [
+            [ copy-nth-of-unsafe ] 4keep
+            [ 1 + ] 2dip 1 +
+        ] dip seq-copy-loop
+    ] if ; inline recursive
+
 PRIVATE>
 
 : subseq-as ( from to seq exemplar -- subseq )
@@ -732,6 +742,9 @@ PRIVATE>
 : nths ( indices seq -- seq' )
     [ [ nth ] curry ] keep map-as ;
 
+: nths-of ( seq indices -- seq' )
+    swap nths ; inline
+
 : any? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
     find drop >boolean ; inline
 
@@ -1168,12 +1181,12 @@ M: repetition sum [ elt>> ] [ length>> ] bi * ; inline
 : map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n )
     [ 0 ] 2dip [ dip + ] with-assoc each ; inline
 
-: count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
-    [ 1 0 ? ] compose map-sum ; inline
-
 : count-by ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
     [ 1 0 ? ] compose map-sum ; inline
 
+: count ( ... seq -- ... n )
+    [ ] count-by ; inline
+
 : cartesian-each ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... )
     [ with each ] 2curry each ; inline