44 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Factor
		
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Factor
		
	
	
USING: help.markup help.syntax sequences ;
 | 
						|
IN: concurrency.combinators
 | 
						|
 | 
						|
HELP: parallel-map
 | 
						|
{ $values { "seq" sequence } { "quot" { $quotation "( elt -- newelt )" } } { "newseq" sequence } }
 | 
						|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to every element of " { $snippet "seq" } ", collecting the results at the end." }
 | 
						|
{ $errors "Throws an error if one of the iterations throws an error." } ;
 | 
						|
 | 
						|
HELP: 2parallel-map
 | 
						|
{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt -- newelt )" } } { "newseq" sequence } }
 | 
						|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", collecting the results at the end." }
 | 
						|
{ $errors "Throws an error if one of the iterations throws an error." } ;
 | 
						|
 | 
						|
HELP: parallel-each
 | 
						|
{ $values { "seq" sequence } { "quot" { $quotation "( elt -- )" } } }
 | 
						|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to every element of " { $snippet "seq" } ", blocking until all quotations complete." }
 | 
						|
{ $errors "Throws an error if one of the iterations throws an error." } ;
 | 
						|
 | 
						|
HELP: 2parallel-each
 | 
						|
{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt -- )" } } }
 | 
						|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", blocking until all quotations complete." }
 | 
						|
{ $errors "Throws an error if one of the iterations throws an error." } ;
 | 
						|
 | 
						|
HELP: parallel-filter
 | 
						|
{ $values { "seq" sequence } { "quot" { $quotation "( elt -- ? )" } } { "newseq" sequence } }
 | 
						|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to every element of " { $snippet "seq" } ", collecting the elements for which the quotation yielded a true value." }
 | 
						|
{ $errors "Throws an error if one of the iterations throws an error." } ;
 | 
						|
 | 
						|
ARTICLE: "concurrency.combinators" "Concurrent combinators"
 | 
						|
"The " { $vocab-link "concurrency.combinators" } " vocabulary provides concurrent variants of various combinators."
 | 
						|
$nl
 | 
						|
"Concurrent sequence combinators:"
 | 
						|
{ $subsection parallel-each }
 | 
						|
{ $subsection 2parallel-each }
 | 
						|
{ $subsection parallel-map }
 | 
						|
{ $subsection 2parallel-map }
 | 
						|
{ $subsection parallel-filter }
 | 
						|
"Concurrent cleave combinators:"
 | 
						|
{ $subsection parallel-cleave }
 | 
						|
{ $subsection parallel-spread }
 | 
						|
{ $subsection parallel-napply } ;
 | 
						|
 | 
						|
ABOUT: "concurrency.combinators"
 |