]> gitweb.factorcode.org Git - factor.git/commitdiff
concurrency.combinators: adding parallel-product-map, docs for stack effects.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Oct 2013 17:45:15 +0000 (10:45 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Oct 2013 17:45:15 +0000 (10:45 -0700)
basis/concurrency/combinators/combinators-docs.factor
basis/concurrency/combinators/combinators.factor

index c3389a1aec2f5fe104d2445a62ef81c0a4ccf133..e0071ce8ddb9162fc18b0a706454f98e7a77381b 100644 (file)
@@ -7,7 +7,7 @@ HELP: parallel-map
 { $errors "Throws an error if one of the iterations throws an error." } ;\r
 \r
 HELP: 2parallel-map\r
-{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt -- newelt )" } } { "newseq" sequence } }\r
+{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt1 elt2 -- newelt )" } } { "newseq" sequence } }\r
 { $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", collecting the results at the end." }\r
 { $errors "Throws an error if one of the iterations throws an error." } ;\r
 \r
@@ -17,7 +17,7 @@ HELP: parallel-each
 { $errors "Throws an error if one of the iterations throws an error." } ;\r
 \r
 HELP: 2parallel-each\r
-{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt -- )" } } }\r
+{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt1 elt2 -- )" } } }\r
 { $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", blocking until all quotations complete." }\r
 { $errors "Throws an error if one of the iterations throws an error." } ;\r
 \r
@@ -34,6 +34,7 @@ $nl
     parallel-each\r
     2parallel-each\r
     parallel-map\r
+    parallel-product-map\r
     2parallel-map\r
     parallel-filter\r
 }\r
index 306242d3acc88b9a48199b6ffa090de4eff7fd75..537b9c043dd84149cfc81e2334fc9e808b005380 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: concurrency.futures concurrency.count-downs sequences
-kernel macros fry combinators generalizations ;
+USING: combinators concurrency.count-downs concurrency.futures
+fry generalizations kernel macros sequences sequences.product ;
 IN: concurrency.combinators
 
 <PRIVATE
@@ -11,17 +11,17 @@ IN: concurrency.combinators
 
 PRIVATE>
 
-: parallel-each ( seq quot -- )
+: parallel-each ( seq quot: ( elt -- ) -- )
     over length [
         '[ _ curry _ spawn-stage ] each
     ] (parallel-each) ; inline
 
-: 2parallel-each ( seq1 seq2 quot -- )
+: 2parallel-each ( seq1 seq2 quot: ( elt1 elt2 -- ) -- )
     2over min-length [
         '[ _ 2curry _ spawn-stage ] 2each
     ] (parallel-each) ; inline
 
-: parallel-filter ( seq quot -- newseq )
+: parallel-filter ( seq quot: ( elt -- ? ) -- newseq )
     over [ selector [ parallel-each ] dip ] dip like ; inline
 
 <PRIVATE
@@ -33,10 +33,13 @@ PRIVATE>
 
 PRIVATE>
 
-: parallel-map ( seq quot -- newseq )
+: parallel-map ( seq quot: ( elt -- newelt ) -- newseq )
     [future] map future-values ; inline
 
-: 2parallel-map ( seq1 seq2 quot -- newseq )
+: parallel-product-map ( seq quot: ( elt -- newelt ) -- newseq )
+    [ <product-sequence> ] dip parallel-map ;
+
+: 2parallel-map ( seq1 seq2 quot: ( elt1 elt2 -- newelt ) -- newseq )
     '[ _ 2curry future ] 2map future-values ;
 
 <PRIVATE