Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
42 lines
1.0 KiB
Plaintext
42 lines
1.0 KiB
Plaintext
type Func = (...args: any[]) => any;
|
|
export interface Cache<
|
|
K,
|
|
V
|
|
> {
|
|
create: CacheCreateFunc<K, V>;
|
|
}
|
|
interface CacheCreateFunc<
|
|
K,
|
|
V
|
|
> {
|
|
(): DefaultCache<K, V>;
|
|
}
|
|
interface DefaultCache<
|
|
K,
|
|
V
|
|
> {
|
|
get(key: K): V | undefined;
|
|
set(key: K, value: V | undefined): void;
|
|
}
|
|
export type Serializer = (args: any[]) => string;
|
|
export interface Options<F extends Func> {
|
|
cache?: Cache<string, ReturnType<F>>;
|
|
serializer?: Serializer;
|
|
strategy?: MemoizeFunc<F>;
|
|
}
|
|
export interface ResolvedOptions<F extends Func> {
|
|
cache: Cache<string, ReturnType<F>>;
|
|
serializer: Serializer;
|
|
}
|
|
export interface MemoizeFunc<F extends Func> {
|
|
(fn: F, options?: Options<F>): F;
|
|
}
|
|
export declare function memoize<F extends Func>(fn: F, options?: Options<F>): F;
|
|
export type StrategyFn = <F extends Func>(this: unknown, fn: F, cache: DefaultCache<string, ReturnType<F>>, serializer: Serializer, arg: any) => any;
|
|
export interface Strategies<F extends Func> {
|
|
variadic: MemoizeFunc<F>;
|
|
monadic: MemoizeFunc<F>;
|
|
}
|
|
export declare const strategies: Strategies<Func>;
|
|
export {};
|