(arg: T)
| 14 | const cache: Map<T, U> = new Map(); |
| 15 | |
| 16 | function wrapper(arg: T): U { |
| 17 | let cachedValue: U | undefined = cache.get(arg); |
| 18 | |
| 19 | if (cachedValue == null) { |
| 20 | cachedValue = func(arg); |
| 21 | cache.set(arg, cachedValue); |
| 22 | } |
| 23 | |
| 24 | return cachedValue; |
| 25 | } |
| 26 | |
| 27 | return wrapper; |
| 28 | } |