add Primitive type
This commit is contained in:
+6
-2
@@ -1,3 +1,5 @@
|
||||
import type { Primitive } from "#/engine/lib/Primitive.ts";
|
||||
|
||||
export type Cache<T> = {
|
||||
clear(): void;
|
||||
delete(key: unknown): boolean;
|
||||
@@ -22,8 +24,10 @@ export function withCache<T, U extends (...args: Parameters<U>) => T>(
|
||||
};
|
||||
}
|
||||
|
||||
export function memoize<T, U>(fn: (arg: U) => T): [(arg: U) => T, Cache<T>] {
|
||||
const cache = new Map<unknown, T>();
|
||||
export function memoize<T, U extends Primitive>(
|
||||
fn: (arg: U) => T,
|
||||
): [(arg: U) => T, Cache<T>] {
|
||||
const cache = new Map<Primitive, T>();
|
||||
const callback = withCache(fn, cache);
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user