source: node_modules/ramda/es/both.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.5 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import _isFunction from "./internal/_isFunction.js";
3import and from "./and.js";
4import 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
37var 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
45export default both;
Note: See TracBrowser for help on using the repository browser.