map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
Factor handbook » The language » Collections » Sequence operations » Sequence combinators

Prev:map ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )
Next:map-index ( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq )


Vocabulary
sequences

Inputs
seqa sequence
quota quotation with stack effect ( ... elt -- ... newelt )
exemplara sequence


Outputs
newseqa new sequence


Word description
Applies the quotation to each element of the sequence in order. The new elements are collected into a sequence of the same class as exemplar.

Examples
The following example converts a string into an array of one-element strings:
USING: prettyprint strings sequences ; "Hello" [ 1string ] { } map-as .
{ "H" "e" "l" "l" "o" }

Note that map could not be used here, because it would create another string to hold results, and one-element strings cannot themselves be elements of strings.

See also
map, map!, map-index, map-index-as

Definition


: map-as
( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
[ length-operator ] dip map-integers-as ; inline