• Wrap fn with a cache indexed by K.

    Type Parameters

    • Ts extends any[]

    • V

    • K = Ts[0]

    Parameters

    • fn: ((...ts) => V)

      function to cache

        • (...ts): V
        • Parameters

          • Rest ...ts: Ts

          Returns V

    • getK: ((...ts) => K) | (Ts extends [K]
          ? undefined
          : never)

      optional function to extract K from Ts

    Returns ((...ts) => V)

    cached function

      • (...ts): V
      • Parameters

        • Rest ...ts: Ts

        Returns V

    Example

    sort(ts, cache(t => "heavy compute..."))
    

Generated using TypeDoc