UNPKG

@miyauci/memo

Version:

Memoization tools, TC39 proposal-function-memo implementation

24 lines (23 loc) 686 B
/** * Polyfill affects the global object. You must be very careful when using it. * * @example * ```ts * import "https://deno.land/x/memoization@$VERSION/polyfill.ts"; * * const fib = ((num: number): number => { * if (num < 2) return num; * * return fib(num - 1) + fib(num - 2); * }).memo(); * * fib(1000); * ``` */ import { type MapLike } from "./memo.js"; declare global { interface Function { /** Returns the proxy function whose call is monitored. It calls at most once for each given arguments. */ memo<T extends (...args: any) => any>(this: T, cache?: MapLike<object, ReturnType<T>>, keying?: (args: Parameters<T>) => unknown[]): T; } }