Handbook
Glossary
map-index-as ( ... seq quot: ( ... elt index -- ... newelt ) exemplar -- ... newseq )
Factor handbook
»
The language
»
Collections
»
Sequence operations
»
Sequence combinators
Prev:
map-index ( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq )
Next:
map-reduce ( ..a seq map-quot: ( ..a elt -- ..a intermediate ) reduce-quot: ( ..a prev intermediate -- ..a next ) -- ..a result )
Vocabulary
sequences
Inputs
seq
a
sequence
quot
a
quotation
with stack effect
( ... elt index -- ... newelt )
exemplar
a
sequence
Outputs
newseq
a
sequence
Word description
Calls the quotation with the element of the sequence and its index on the stack, with the index on the top of the stack. Collects the outputs of the quotation and outputs them in a sequence of the same type as the
exemplar
sequence.
Examples
USING: arrays sequences prettyprint ; { 10 20 30 } [ 2array ] V{ } map-index-as .
V{ { 10 0 } { 20 1 } { 30 2 } }
See also
map
,
map!
,
map-as
,
map-index
Definition
USING:
kernel
;
IN:
sequences
:
map-index-as
( ... seq quot: ( ... elt index -- ... newelt ) exemplar -- ... newseq )
[
dup
length
<iota>
]
2dip
2map-as
;
inline