Function memoize

Memoizes a function, caching results based on arguments. Works best with pure functions with small input spaces.

The cache key is the JSON form of the arguments, so objects and arrays match by content, not identity. undefined, NaN, Infinity, -Infinity and BigInt values get their own keys. Functions and symbols match by identity. -0 and 0 share a key. Circular arguments throw a TypeError; Map and Set arguments are not told apart by content. A key that contains the literal "\u0000mochila" property can collide.

const expensiveSum = (a: number, b: number) => {
console.log('computing...');
return a + b;
};
const memoized = memoize(expensiveSum);
memoized(2, 3); // logs 'computing...'
memoized(2, 3); // returns cached result