UNPKG

@casual-simulation/aux-common

Version:
22 lines 641 B
/** * Calculates the result of the given function - caching it if needed. * @param name The name of the function. * @param func The function to cache. * @param args The arguments that should be used to determine when to reuse the cached results */ export function cacheFunction(calc, name, func, ...args) { if (!calc) { return func(); } let key = name; for (let arg of args) { key += `-${arg}`; } if (calc.cache.has(key)) { return calc.cache.get(key); } const result = func(); calc.cache.set(key, result); return result; } //# sourceMappingURL=BotCalculationContext.js.map