/** * @public * 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. * @param map - The `Map` to search and modify. * @param key - The key to search for / set in `map`. * @param getValue - The function to call if a value is not found. * @returns The value in `map`, otherwise the result of the `getValue`. * * @remarks * See {@link (mapInitializeGet:1)}. */ export function mapInitializeGet ( map: Map, key: TKey, getValue: (key: TKey) => TValue, ) : TMapValue; /** * @public * {@inheritDoc (mapInitializeGet: 1)} */ export function mapInitializeGet ( map: WeakMap, key: TKey, getValue: (key: TKey) => TValue, ) : TMapValue; export function mapInitializeGet ( map: Map | WeakMap, key: TKey, getValue: (key: TKey) => TValue, ) : TMapValue { let value = map.get(key); if (value !== undefined) { return value; } value = getValue(key); map.set(key, value); return value; }