Home > rc-js-util > mapInitializeGet
Gets the value from a Map
for a given key, where the value is undefined
or hasn’t been set, the callback’s return will be inserted into the Map
and returned.
Signature:
export declare function mapInitializeGet<TMapKey, TKey extends TMapKey, TMapValue, TValue extends TMapValue>(map: Map<TMapKey, TMapValue>, key: TKey, getValue: (key: TKey) => TValue): TMapValue;
Parameter | Type | Description |
---|---|---|
map | Map<TMapKey, TMapValue> | The Map to search and modify. |
key | TKey | The key to search for / set in map . |
getValue | (key: TKey) => TValue | The function to call if a value is not found. |
Returns:
TMapValue
The value in map
, otherwise the result of the getValue
.
See mapInitializeGet().