trie-memoize
Version:
A memoization algorithm in which each function argument represents a new key, creating a trie of caches as defined by the array in your first argument.
14 lines (13 loc) • 341 B
TypeScript
export interface MapLike {
new (...args: any[]): any
}
export declare type CacheConstructor =
| MapConstructor
| WeakMapConstructor
| MapLike
| Record<any, any>
declare const memoize: <T extends any[], U extends unknown>(
mapConstructors: CacheConstructor[],
fn: (...args: T) => U
) => (...args: T) => U
export default memoize