File size: 248 Bytes
56fda74
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
export default function memoize<V>(fn: (arg: string) => V): (arg: string) => V {
  const cache: Record<string, V> = Object.create(null)

  return (arg: string) => {
    if (cache[arg] === undefined) cache[arg] = fn(arg)
    return cache[arg]
  }
}