Skip to content

Commit

Permalink
Generalize unaryMemoize to efficiently support undefined results
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Jul 12, 2023
1 parent c1c31de commit 80ab7d6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ function unaryMemoize<K, V>(fn: (arg: K) => V, prepopulate: K[] = []) {
const cache = new Map(prepopulate.map(arg => [arg, fn(arg)]));
return (arg: K) => {
let value = cache.get(arg);
if (!value) {
if (value === undefined && !cache.has(arg)) {
value = fn(arg);
cache.set(arg, value);
}
return value;
return value as V;
};
}

0 comments on commit 80ab7d6

Please sign in to comment.