rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
92 lines (43 loc) • 1.41 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [rc-js-util](./rc-js-util.md) > [mapInitializeGet](./rc-js-util.mapinitializeget_1.md)
## mapInitializeGet() function
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:**
```typescript
export declare function mapInitializeGet<TMapKey extends object, TKey extends TMapKey, TMapValue, TValue extends TMapValue>(map: WeakMap<TMapKey, TMapValue>, key: TKey, getValue: (key: TKey) => TValue): TMapValue;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
map
</td><td>
WeakMap<TMapKey, TMapValue>
</td><td>
The `Map` to search and modify.
</td></tr>
<tr><td>
key
</td><td>
TKey
</td><td>
The key to search for / set in `map`<!-- -->.
</td></tr>
<tr><td>
getValue
</td><td>
(key: TKey) => TValue
</td><td>
The function to call if a value is not found.
</td></tr>
</tbody></table>
**Returns:**
TMapValue
The value in `map`<!-- -->, otherwise the result of the `getValue`<!-- -->.
## Remarks
See [mapInitializeGet()](./rc-js-util.mapinitializeget.md)<!-- -->.