add Primitive type

This commit is contained in:
Schluffe
2026-08-28 13:33:23 +02:00
parent 51c1fc249d
commit 71cfa64793
6 changed files with 34 additions and 22 deletions
+6 -2
View File
@@ -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 [