]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: adding each-from and reduce-from.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 14 May 2012 23:43:42 +0000 (16:43 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 14 May 2012 23:43:42 +0000 (16:43 -0700)
extra/sequences/extras/extras.factor

index 31e16c9c9d8f36f241e62f695589ae35c651c6fa..5faff7763429041eff54cfb335b33a7abb7ca6ee 100644 (file)
@@ -27,6 +27,12 @@ IN: sequences.extras
 : insert-sorted ( elt seq -- seq )
     2dup [ < ] with find drop over length or swap insert-nth ;
 
+: each-from ( ... seq quot: ( ... x -- ... ) i -- ... )
+    -rot (each) (each-integer) ; inline
+
+: reduce-from ( ... seq identity quot: ( ... prev elt -- ... next ) i -- ... result )
+    [ swap ] 2dip each-from ; inline
+
 : max-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
     [ bi@ dupd max = ] curry most ; inline