UNPKG

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.38 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [rc-js-util](./rc-js-util.md) &gt; [mapInitializeGet](./rc-js-util.mapinitializeget.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, TKey extends TMapKey, TMapValue, TValue extends TMapValue>(map: Map<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> Map&lt;TMapKey, TMapValue&gt; </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) =&gt; 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)<!-- -->.