1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _isFunction =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_isFunction");
|
8 |
|
9 | var lift =
|
10 | /*#__PURE__*/
|
11 | require("./lift");
|
12 |
|
13 | var or =
|
14 | /*#__PURE__*/
|
15 | require("./or");
|
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.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 |
|
48 | var 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 |
|
56 | module.exports = either; |
\ | No newline at end of file |