Function memoize

A memoization function that caches the result of a function based on its arguments.

  • Type Parameters

    • T extends ((...args: A) => any)

      The function type that will be memoized

    • A extends any[]

      The argument types of the function

    • K = string

      The key type used to store the memoized results

    Parameters

    • key: ((args: A) => K)

      A function that generates a unique key based on the arguments of the original function

        • (args): K
        • Parameters

          • args: A

          Returns K

    • run: T

      The original function to be memoized

    Returns T & IClearable<K> & IControl<K, ReturnType<T>>

    • A memoized version of the original function with the ability to clear the cache