MCPcopy
hub / github.com/TypeStrong/ts-node / cachedLookup

Function cachedLookup

src/util.ts:82–93  ·  view source on GitHub ↗
(fn: (arg: T) => R)

Source from the content-addressed store, hash-verified

80 * Cached fs operation wrapper.
81 */
82export function cachedLookup<T, R>(fn: (arg: T) => R): (arg: T) => R {
83 const cache = new Map<T, R>();
84
85 return (arg: T): R => {
86 if (!cache.has(arg)) {
87 const v = fn(arg);
88 cache.set(arg, v);
89 return v;
90 }
91 return cache.get(arg)!;
92 };
93}
94
95/**
96 * @internal

Callers 3

ts-internals.tsFile · 0.90

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…