ts-data-forge
    Preparing search index...
    • Creates a memoized version of a function that caches results based on input arguments.

      The memoized function stores results in an internal Map and returns cached values for repeated calls with the same arguments. This can significantly improve performance for expensive computations or I/O operations.

      Important considerations:

      • The cache grows unbounded - consider memory implications for long-running applications
      • Cache keys must be primitives (string, number, boolean, symbol, null, undefined, bigint)
      • Object arguments require careful key generation to ensure uniqueness
      • Pure functions only - memoizing functions with side effects can lead to bugs

      Type Parameters

      • const A extends readonly unknown[]

        The tuple type of the function arguments

      • R

        The return type of the function

      • K extends Primitive

        The primitive type used as the cache key (must be valid Map key)

      Parameters

      • fn: (...args: A) => R

        The pure function to memoize

      • argsToCacheKey: (...args: A) => K

        Function that converts arguments to a unique cache key

      Returns (...args: A) => R

      A memoized version of the input function with the same signature