source: node_modules/ramda/src/either.js@ d24f17c

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

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var _isFunction =
6/*#__PURE__*/
7require("./internal/_isFunction.js");
8
9var lift =
10/*#__PURE__*/
11require("./lift.js");
12
13var or =
14/*#__PURE__*/
15require("./or.js");
16/**
17 * A function wrapping calls to the two functions in an `||` operation,
18 * returning the result of the first function if it is truth-y and the result
19 * of the second function otherwise. Note that this is short-circuited,
20 * meaning that the second function will not be invoked if the first returns a
21 * truth-y value.
22 *
23 * In addition to functions, `R.either` also accepts any fantasy-land compatible
24 * applicative functor.
25 *
26 * @func
27 * @memberOf R
28 * @since v0.12.0
29 * @category Logic
30 * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
31 * @param {Function} f a predicate
32 * @param {Function} g another predicate
33 * @return {Function} a function that applies its arguments to `f` and `g` and `||`s their outputs together.
34 * @see R.both, R.anyPass, R.or
35 * @example
36 *
37 * const gt10 = x => x > 10;
38 * const even = x => x % 2 === 0;
39 * const f = R.either(gt10, even);
40 * f(101); //=> true
41 * f(8); //=> true
42 *
43 * R.either(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(55)
44 * R.either([false, false, 'a'], [11]) // => [11, 11, "a"]
45 */
46
47
48var either =
49/*#__PURE__*/
50_curry2(function either(f, g) {
51 return _isFunction(f) ? function _either() {
52 return f.apply(this, arguments) || g.apply(this, arguments);
53 } : lift(or)(f, g);
54});
55
56module.exports = either;
Note: See TracBrowser for help on using the repository browser.