Options
All
  • Public
  • Public/Protected
  • All
Menu

Module function/memoize/with

Index

References

Type aliases

Functions

References

Renames and re-exports memoizeWith

Type aliases

CacheFunc: () => ReturnType<typeof createCache>

Type declaration

Hasher: (...args: any) => string

Type declaration

    • (...args: any): string
    • Parameters

      • Rest ...args: any

      Returns string

Functions

  • memoizeWith is a memoize function fabric. It has simple classic memoization signature. Use it to build your own memoization function.

    It takes three params:

    1. function that will be used to create cache object. Cache must have three methods - get, has, set. So it's compatible with Map, WeakMap, LRU (https://www.npmjs.com/package/lru-cache) instances.
    2. function that will be used to create hash key for cache lookup. It is invoked with arguments for result function.
    3. function, that will be memoized.
    example
     const createCache = () => new Map();
    const hasher = (...args) => JSON.stringify(args);
    const memoize = memoizeWith(createCache, hasher);

    const add = (a,b) => a + b;
    const memoizeAdd = memoize(add);
    const sum = add(1,3); // from original add call
    const sum = add(1,4); // from original add call
    const sum = add(1,3); // from cache

    Type parameters

    • T: Function

    Parameters

    Returns T

  • memoizeWith is a memoize function fabric. It has simple classic memoization signature. Use it to build your own memoization function.

    It takes three params:

    1. function that will be used to create cache object. Cache must have three methods - get, has, set. So it's compatible with Map, WeakMap, LRU (https://www.npmjs.com/package/lru-cache) instances.
    2. function that will be used to create hash key for cache lookup. It is invoked with arguments for result function.
    3. function, that will be memoized.
    example
     const createCache = () => new Map();
    const hasher = (...args) => JSON.stringify(args);
    const memoize = memoizeWith(createCache, hasher);

    const add = (a,b) => a + b;
    const memoizeAdd = memoize(add);
    const sum = add(1,3); // from original add call
    const sum = add(1,4); // from original add call
    const sum = add(1,3); // from cache

    Parameters

    Returns <T>(fn: T) => T

      • <T>(fn: T): T
      • Type parameters

        • T: Function

        Parameters

        • fn: T

        Returns T

  • memoizeWith is a memoize function fabric. It has simple classic memoization signature. Use it to build your own memoization function.

    It takes three params:

    1. function that will be used to create cache object. Cache must have three methods - get, has, set. So it's compatible with Map, WeakMap, LRU (https://www.npmjs.com/package/lru-cache) instances.
    2. function that will be used to create hash key for cache lookup. It is invoked with arguments for result function.
    3. function, that will be memoized.
    example
     const createCache = () => new Map();
    const hasher = (...args) => JSON.stringify(args);
    const memoize = memoizeWith(createCache, hasher);

    const add = (a,b) => a + b;
    const memoizeAdd = memoize(add);
    const sum = add(1,3); // from original add call
    const sum = add(1,4); // from original add call
    const sum = add(1,3); // from cache

    Parameters

    Returns { <T>(hasher: Hasher, fn: T): T; (hasher: Hasher): <T>(fn: T) => T }

      • <T>(hasher: Hasher, fn: T): T
      • (hasher: Hasher): <T>(fn: T) => T
      • Type parameters

        • T: Function

        Parameters

        Returns T

      • Parameters

        Returns <T>(fn: T) => T

          • <T>(fn: T): T
          • Type parameters

            • T: Function

            Parameters

            • fn: T

            Returns T

Generated using TypeDoc