import { memo } from "https://deno.land/x/memoization@1.2.0/memo.ts";
Returns the proxy function whose call is monitored. It calls at most once for each given arguments.
Examples
Example 1
Example 1
import { memo } from "https://deno.land/x/memoization@$VERSION/memo.ts";
function f(x: number): number {
console.log(x);
return x * 2;
}
const fMemo = memo(f);
fMemo(3); // Prints 3 and returns 6.
fMemo(3); // Does not print anything. Returns 6.
fMemo(2); // Prints 2 and returns 4.
fMemo(2); // Does not print anything. Returns 4.
fMemo(3); // Does not print anything. Returns 6.
Either version would work with recursive functions: