typedash
Version:
modern, type-safe collection of utility functions
17 lines (16 loc) • 500 B
JavaScript
// 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;
};
}
export { memoize };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-TNVZKQSV.js.map