/function/memoizeShallow
stdMemoizes the function result so it is not computed for the same parameters. Uses shallow equality.
Type signature
<TResult>(f: (...xs: unknown[]) => TResult) => (...args: unknown[]) => TResult
Examples
const f = ({ x }) => {
console.log(x);
return x + 1;
};
const memoized = memoizeShallow(f);
memoized({ x: 5 });
memoized({ x: 5 });
memoized({ x: 5 });
memoized({ x: 3 });
Try in REPL
Questions
- How to memoize a function with shallow equality?