source: node_modules/ramda/es/either.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.4 KB
RevLine 
[d24f17c]1import _curry2 from "./internal/_curry2.js";
2import _isFunction from "./internal/_isFunction.js";
3import lift from "./lift.js";
4import 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
36var 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
44export default either;
Note: See TracBrowser for help on using the repository browser.