UNPKG

@rimbu/common

Version:

Common types and objects used in many other Rimbu packages

48 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OptLazyOr = exports.OptLazy = void 0; var tslib_1 = require("tslib"); /** * Returns the value contained in an `OptLazy` instance of type T. * @param optLazy - the `OptLazy` value of type T * @param args - when needed, the extra arguments to pass to the lazy invocation * @typeparam T - the value type * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case * @example * ```ts * OptLazy(1) // => 1 * OptLazy(() => 1) // => 1 * OptLazy(() => () => 1) // => () => 1 * ``` */ function OptLazy(optLazy) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (optLazy instanceof Function) return optLazy.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false)); return optLazy; } exports.OptLazy = OptLazy; /** * Returns the value contained in an `OptLazyOr` instance of type T, or the given * `otherValue` if the lazy function returns it. * @param optLazyOr - a value or a function returning a value or otherwise the received value * @param otherValue - the value to return if the optLazyOr does not return its own value * @typeparam T - the value type * @typeparam O - the default value type * @example * ```ts * OptLazyOr(1, 'a') // => 1 * OptLazyOr(() => 1, 'a') // => 1 * OptLazyOr((none) => none, 'a') // => 'a' * ``` */ function OptLazyOr(optLazyOr, otherValue) { if (optLazyOr instanceof Function) return optLazyOr(otherValue); return optLazyOr; } exports.OptLazyOr = OptLazyOr; //# sourceMappingURL=optlazy.cjs.map