summaryrefslogtreecommitdiff
path: root/u/leftpadesque/memoize.ts
diff options
context:
space:
mode:
Diffstat (limited to 'u/leftpadesque/memoize.ts')
-rw-r--r--u/leftpadesque/memoize.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/u/leftpadesque/memoize.ts b/u/leftpadesque/memoize.ts
index 95e6019..541bd20 100644
--- a/u/leftpadesque/memoize.ts
+++ b/u/leftpadesque/memoize.ts
@@ -1,14 +1,14 @@
-import type { Callable } from "@emprespresso/pengueno";
+import type { Callable } from '@emprespresso/pengueno';
export const memoize = <R, F extends Callable<R>>(fn: F): F => {
- const cache = new Map<string, R>();
- return ((...args: unknown[]): R => {
- const key = JSON.stringify(args);
- if (cache.has(key)) {
- return cache.get(key)!;
- }
- const res = fn.apply(args);
- cache.set(key, res);
- return res;
- }) as F;
+ const cache = new Map<string, R>();
+ return ((...args: unknown[]): R => {
+ const key = JSON.stringify(args);
+ if (cache.has(key)) {
+ return cache.get(key)!;
+ }
+ const res = fn.apply(args);
+ cache.set(key, res);
+ return res;
+ }) as F;
};