(map: Map<K, V>, key: K, factory: () => V)
| 7 | * @returns The existing value, or the new one if constructed |
| 8 | */ |
| 9 | export function getDefault<K, V>(map: Map<K, V>, key: K, factory: () => V): V { |
| 10 | let currentValue = map.get(key); |
| 11 | |
| 12 | if (currentValue == null) { |
| 13 | currentValue = factory(); |
| 14 | map.set(key, currentValue); |
| 15 | } |
| 16 | |
| 17 | return currentValue; |
| 18 | } |
no test coverage detected