2map-reduce ( ..a seq1 seq2 map-quot: ( ..a elt1 elt2 -- ..a intermediate ) reduce-quot: ( ..a prev intermediate -- ..a next ) -- ..a result )
Factor handbook » The language » Collections » Sequence operations » Sequence combinators » Pair-wise sequence combinators

Prev:2map-as ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... newelt ) exemplar -- ... newseq )
Next:2all? ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ? ) -- ... ? )


Vocabulary
sequences

Inputs
seq1a sequence
seq2a sequence
map-quota quotation with stack effect ( ..a elt1 elt2 -- ..a intermediate )
reduce-quota quotation with stack effect ( ..a prev intermediate -- ..a next )


Outputs
resultan object


Word description
Calls map-quot on each pair of elements from seq1 and seq2 and combines the results using reduce-quot in the same manner as reduce, except that there is no identity element, and the sequence must have a length of at least 1.

Errors
Throws an error if the sequence is empty.

Examples
USING: sequences prettyprint math ; { 10 30 50 } { 200 400 600 } [ + ] [ + ] 2map-reduce .
1290


Definition


: 2map-reduce
( ..a seq1 seq2 map-quot: ( ..a elt1 elt2 -- ..a intermediate ) reduce-quot: ( ..a prev intermediate -- ..a next ) -- ..a result )
[ [ [ [ first ] bi@ ] 2keep ] dip [ 2dip ] keep ] dip
[ [ [ rot ] ] dip [ dip swap ] curry compose ] dip compose
1 2each-from ; inline