Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

memoize

import { memoize } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/fn.ts";

Memoize a unary function using a Map. This means that this algorithm puposefully leaks memory.

TODO: Extend memoize to be variadic.

@example
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
function memoize<D, A>(ua: Fn<D, A>): Fn<D, A>;
§
memoize<D, A>(ua: Fn<D, A>): Fn<D, A>
[src]

§Type Parameters

§Parameters

§
ua: Fn<D, A>
[src]

§Return Type

§
Fn<D, A>
[src]