diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-06-20 14:53:38 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-06-20 14:53:38 -0700 |
commit | d4791f3d357634daf506fb8f91cc5332a794c421 (patch) | |
tree | 1bb01d2d4d8fa74d83bb6f99f2c8aa4146ca2d11 /u/leftpadesque/memoize.ts | |
parent | d7e8d31c94cd713a2f4cf799e20e993acc69e361 (diff) | |
download | ci-d4791f3d357634daf506fb8f91cc5332a794c421.tar.gz ci-d4791f3d357634daf506fb8f91cc5332a794c421.zip |
Move to nodejs
Diffstat (limited to 'u/leftpadesque/memoize.ts')
-rw-r--r-- | u/leftpadesque/memoize.ts | 22 |
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; }; |