2map-reduce ( ..a seq1 seq2 map-quot: ( ..a elt1 elt2 -- ..b intermediate ) reduce-quot: ( ..b 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 and outputs
seq1a sequence
seq2a sequence
map-quota quotation with stack effect ( ..a elt1 elt2 -- ..b intermediate )
reduce-quota quotation with stack effect ( ..b prev intermediate -- ..a next )
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 -- ..b intermediate ) reduce-quot: ( ..b prev intermediate -- ..a next ) -- ..a result )
[ [ 2dup [ first ] bi@ ] dip [ call ] keep ] dip compose
[ -rot ] dip 1 2each-from ; inline