Skip to main content
Module

x/911/src/memoize.ts>memoized

Opinionated collection of helper tools. Assembled with Deno in mind.
Go to Latest
function memoized
import { memoized } from "https://deno.land/x/911@0.1.1/src/memoize.ts";

TypeScript Decorator to memoize a function. Accepts same options as memoize.

Examples

Example 1

import { memoized } from "https://deno.land/x/911@0.1.1/src/memoize.ts";

const cache = new Map();
class MyClass {
  // The quotes are to stop JSDoc from breaking on the "@".
  // You should not use quotes in your actual code.
  "@memoized"({ cache })
  public myMethod() {
    return Promise.resolve(1);
  }
}

Type Parameters

A extends unknown[]
R
T

Parameters

optional
options: MemoizeOptions<A, R> = [UNSUPPORTED]

Define your own cache or hash function (both optional).

Returns

MemoizeDecoratorFactory<A, R, T>