rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
23 lines • 539 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fpOnce = void 0;
/**
* @public
* Creates a function that can be called many times but will run at most once.
*
* @remarks
* See {@link fpOnce}.
*/
function fpOnce(initialize) {
let item;
let initialized = false;
return (...args) => {
if (initialized) {
return item;
}
initialized = true;
return item = initialize(...args);
};
}
exports.fpOnce = fpOnce;
//# sourceMappingURL=fp-once.js.map