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