export function memoize(fn: (arg: Arg) => Result): (arg: Arg) => Result { const cache = new Map(); return (arg: Arg) => { if (cache.has(arg)) { return cache.get(arg) as Result; } const result = fn(arg); cache.set(arg, result); return result; }; }