UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

23 lines (20 loc) 472 B
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; /** * @template K * @template V * @param {Map<K, V>} map a map * @param {K} key the key * @param {function(): V} computer compute value * @returns {V} value */ exports.provide = (map, key, computer) => { const value = map.get(key); if (value !== undefined) return value; const newValue = computer(); map.set(key, newValue); return newValue; };