test-action-debian-package/node_modules/ramda/es/either.js
Dawid Dziurla 9308795b8b
update
2020-03-26 15:37:35 +01:00

44 lines
1.4 KiB
JavaScript

import _curry2 from "./internal/_curry2.js";
import _isFunction from "./internal/_isFunction.js";
import lift from "./lift.js";
import or from "./or.js";
/**
* A function wrapping calls to the two functions in an `||` operation,
* returning the result of the first function if it is truth-y and the result
* of the second function otherwise. Note that this is short-circuited,
* meaning that the second function will not be invoked if the first returns a
* truth-y value.
*
* In addition to functions, `R.either` also accepts any fantasy-land compatible
* applicative functor.
*
* @func
* @memberOf R
* @since v0.12.0
* @category Logic
* @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
* @param {Function} f a predicate
* @param {Function} g another predicate
* @return {Function} a function that applies its arguments to `f` and `g` and `||`s their outputs together.
* @see R.or
* @example
*
* const gt10 = x => x > 10;
* const even = x => x % 2 === 0;
* const f = R.either(gt10, even);
* f(101); //=> true
* f(8); //=> true
*
* R.either(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(55)
* R.either([false, false, 'a'], [11]) // => [11, 11, "a"]
*/
var either =
/*#__PURE__*/
_curry2(function either(f, g) {
return _isFunction(f) ? function _either() {
return f.apply(this, arguments) || g.apply(this, arguments);
} : lift(or)(f, g);
});
export default either;