Memoizes the function result so it is not computed for the same parameters. Uses deep equality.

Type signature

<TResult>(f: (...xs: unknown[]) => TResult) => (...args: unknown[]) => TResult

Examples

const f = (x) => {
  console.log(x);
  return x + 1;
};

const memoized = memoize(f);

memoized(5);
memoized(5);
memoized(5);
memoized(3);
Try in REPL

Questions

  • How to memoize a function?

TypeScript sourceJavaScript source