assoc-map ( ... assoc quot: ( ... key value -- ... newkey newvalue ) -- ... newassoc ) (original) (raw)

Vocabulary
assocs

Inputs

assoc an assoc
quot a quotation with stack effect ( ... key value -- ... newkey newvalue )

Outputs

newassoc a new assoc

Word description
Applies the quotation to each entry in the input assoc and collects the results in a new assoc of the same type as the input.

Examples

: discount ( prices n -- newprices ) [ - ] curry assoc-map ; H{ { "bananas" 5 } { "apples" 42 } { "pears" 17 } } 2 discount .
H{ { "bananas" 3 } { "apples" 40 } { "pears" 15 } }

See also
assoc-map-as

Definition

USING: kernel ;

IN: assocs

: assoc-map
( ... assoc quot: ( ... key value -- ... newkey newvalue ) -- ... newassoc )
over assoc-map-as ; inline