UNPKG

mocoolka-function

Version:

Function lib for function.

24 lines (23 loc) 1.07 kB
Object.defineProperty(exports, "__esModule", { value: true }); /** * Tests the final argument by passing it to the given predicate function. If * the predicate is not satisfied, the function will return the result of * calling the `whenFalseFn` function with the same argument. If the predicate * is satisfied, the argument is returned as is. * * @since v0.1.0 * @param {Function} pred A predicate function * @param {Function} whenFalseFn A function to invoke when the `pred` evaluates * to a falsy value. * @param {*} x An object to test with the `pred` function and * pass to `whenFalseFn` if necessary. * @return {*} Either `x` or the result of applying `x` to `whenFalseFn`. * @example * * let safeInc = _unless(R.isNil, R.inc); * safeInc(null); //=> null * safeInc(1); //=> 2 */ var unless = function (pred, whenFalseFn, x) { return pred(x) ? x : whenFalseFn(x); }; exports.default = unless; //# sourceMappingURL=unless.js.map