UNPKG

1.17 kBJavaScriptView Raw
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3");
4/**
5 * Tests the final argument by passing it to the given predicate function. If
6 * the predicate is not satisfied, the function will return the result of
7 * calling the `whenFalseFn` function with the same argument. If the predicate
8 * is satisfied, the argument is returned as is.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.18.0
13 * @category Logic
14 * @sig (a -> Boolean) -> (a -> a) -> a -> a
15 * @param {Function} pred A predicate function
16 * @param {Function} whenFalseFn A function to invoke when the `pred` evaluates
17 * to a falsy value.
18 * @param {*} x An object to test with the `pred` function and
19 * pass to `whenFalseFn` if necessary.
20 * @return {*} Either `x` or the result of applying `x` to `whenFalseFn`.
21 * @see R.ifElse, R.when, R.cond
22 * @example
23 *
24 * let safeInc = R.unless(R.isNil, R.inc);
25 * safeInc(null); //=> null
26 * safeInc(1); //=> 2
27 */
28
29
30var unless =
31/*#__PURE__*/
32_curry3(function unless(pred, whenFalseFn, x) {
33 return pred(x) ? x : whenFalseFn(x);
34});
35
36module.exports = unless;
\No newline at end of file