@beenotung/tslib
Version:
utils library in Typescript
28 lines (27 loc) • 834 B
TypeScript
import { MapMap } from './map-map';
/**
* @description support any arguments length, any data type arguments
* do not works for self-recursive functions
* unless it is wrapped when being constructed
*
* Example that works:
*
* const q = memorize((n: number) => n < 2 ? 1 : q(n - 1) + q(n - 2));
*
* Example that do not works:
*
* let f = (n: number) => n < 2 ? 1 : f(n - 1) + f(n - 2);
* f = memorize(f);
*
* */
export declare function memorize<F extends Function>(f: F): F & {
clear: () => void;
cache: MapMap<number, MapMap<any, any>>;
};
export declare class MemorizePool<A> {
cache: MapMap<number, MapMap<any, any>>;
get(args: IArguments): undefined | [A];
set(args: IArguments, res: any): void;
getOrCalc(args: IArguments, f: () => A): A;
private getLastMap;
}