import { memoize } from "https://deno.land/x/fun@v.2.0.0-alpha.11/fn.ts";
Memoize a unary function using a Map. This means that this algorithm puposefully leaks memory.
TODO: Extend memoize to be variadic.
Examples
Example 1
Example 1
import * as F from "./fn.ts";
// Big old expensive recursive algorithm
const fib = (n: number): number =>
n < 1 ? 0 :
n <= 1 ? 1 :
fib(n - 2) + fib(n - 1);
const mfib = F.memoize(fib);
const result1 = mfib(10); // 55
const result2 = mfib(10); // 55 but does not recompute