UNPKG

typia

Version:

Superfast runtime validators with only one line

15 lines (13 loc) 298 B
export namespace MapUtil { export const take = <Key, T>( dict: Map<Key, T>, key: Key, generator: () => T, ): T => { const oldbie: T | undefined = dict.get(key); if (oldbie) return oldbie; const value: T = generator(); dict.set(key, value); return value; }; }