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