Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
map-reduce ( ..a seq map-quot: ( ..a x -- ..b elt ) reduce-quot: ( ..b prev elt -- ..a next ) -- ..a result )
Factor documentation
>
Factor handbook
>
The language
>
Collections
>
Sequence operations
>
Sequence combinators
Prev:
map-index ( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq )
Next:
accumulate ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final newseq )
Vocabulary
sequences
Inputs and outputs
seq
a
sequence
map-quot
a
quotation
reduce-quot
a
quotation
result
an
object
Word description
Calls
map-quot
on each element 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 ; { 1 3 5 } [ sq ] [ + ] map-reduce .
35
Definition
USING:
kernel
;
IN:
sequences
:
map-reduce
( ..a seq map-quot: ( ..a x -- ..b elt ) reduce-quot: ( ..b prev elt -- ..a next ) -- ..a result )
[
[
unclip-slice
]
dip
[
call
]
keep
]
dip
compose
reduce
;
inline