Handbook
Glossary
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
seq1
a
sequence
seq2
a
sequence
map-quot
a
quotation
with stack effect
( ..a elt1 elt2 -- ..a intermediate )
reduce-quot
a
quotation
with stack effect
( ..a prev intermediate -- ..a next )
Outputs
result
an
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
USING:
kernel
;
IN:
sequences
:
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