source: node_modules/ramda/es/unless.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import _curry3 from "./internal/_curry3.js";
2/**
3 * Tests the final argument by passing it to the given predicate function. If
4 * the predicate is not satisfied, the function will return the result of
5 * calling the `whenFalseFn` function with the same argument. If the predicate
6 * is satisfied, the argument is returned as is.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.18.0
11 * @category Logic
12 * @sig (a -> Boolean) -> (a -> b) -> a -> a | b
13 * @param {Function} pred A predicate function
14 * @param {Function} whenFalseFn A function to invoke when the `pred` evaluates
15 * to a falsy value.
16 * @param {*} x An object to test with the `pred` function and
17 * pass to `whenFalseFn` if necessary.
18 * @return {*} Either `x` or the result of applying `x` to `whenFalseFn`.
19 * @see R.ifElse, R.when, R.cond
20 * @example
21 *
22 * let safeInc = R.unless(R.isNil, R.inc);
23 * safeInc(null); //=> null
24 * safeInc(1); //=> 2
25 */
26
27var unless =
28/*#__PURE__*/
29_curry3(function unless(pred, whenFalseFn, x) {
30 return pred(x) ? x : whenFalseFn(x);
31});
32
33export default unless;
Note: See TracBrowser for help on using the repository browser.