2cache ( ... key1 key2 assoc quot: ( ... key1 key2 -- ... value ) -- ... value )
Factor handbook » The language » Collections » Associative mapping operations » Associative mapping combinators

Prev:cache ( ... key assoc quot: ( ... key -- ... value ) -- ... value )


Vocabulary
assocs

Inputs
key1a key
key2a key
assocan assoc
quota quotation with stack effect ( ... key1 key2 -- ... value )


Outputs
valuea previously-retained or freshly-computed value


Word description
If a single key composed of the input keys is present in the assoc, outputs the associated value, otherwise calls the quotation to produce a value and stores the keys/value pair into the assoc. Returns the value stored in the assoc. Returns a value either looked up or newly stored in the assoc.

Side effects
Modifies assoc

Definition


: 2cache
( ... key1 key2 assoc quot: ( ... key1 key2 -- ... value ) -- ... value )
[ 2array ] 2dip [ first2-unsafe ] prepose cache ; inline