map-index ( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq )
Factor documentation > Factor handbook > The language > Collections > Sequence operations > Sequence combinators
Prev:map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
Next:map-reduce ( ..a seq map-quot: ( ..a x -- ..b elt ) reduce-quot: ( ..b prev elt -- ..a next ) -- ..a result )


Vocabulary
sequences

Inputs and outputs
seqa sequence
quota quotation with stack effect ( ... elt index -- ... newelt )
newseqa 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 input sequence.

Examples
USING: arrays sequences prettyprint ; { 10 20 30 } [ 2array ] map-index .
{ { 10 0 } { 20 1 } { 30 2 } }


Definition
USING: kernel ;

IN: sequences

: map-index
( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq )
[ dup length iota ] dip 2map ; inline