UNPKG

typedash

Version:

modern, type-safe collection of utility functions

19 lines (17 loc) 514 B
'use strict'; // src/functions/memoize/memoize.ts function memoize(fn, cacheKeyResolver) { const cache = /* @__PURE__ */ new Map(); return function memoizedFunction(...args) { const cacheKey = cacheKeyResolver ? cacheKeyResolver(...args) : args[0]; if (cache.has(cacheKey)) { return cache.get(cacheKey); } const result = fn(...args); cache.set(cacheKey, result); return result; }; } exports.memoize = memoize; //# sourceMappingURL=out.js.map //# sourceMappingURL=index.cjs.map