UNPKG

1.45 kBJavaScriptView Raw
1var _curry1 =
2/*#__PURE__*/
3require("./internal/_curry1");
4
5var curryN =
6/*#__PURE__*/
7require("./curryN");
8
9var max =
10/*#__PURE__*/
11require("./max");
12
13var pluck =
14/*#__PURE__*/
15require("./pluck");
16
17var reduce =
18/*#__PURE__*/
19require("./reduce");
20/**
21 * Takes a list of predicates and returns a predicate that returns true for a
22 * given list of arguments if every one of the provided predicates is satisfied
23 * by those arguments.
24 *
25 * The function returned is a curried function whose arity matches that of the
26 * highest-arity predicate.
27 *
28 * @func
29 * @memberOf R
30 * @since v0.9.0
31 * @category Logic
32 * @sig [(*... -> Boolean)] -> (*... -> Boolean)
33 * @param {Array} predicates An array of predicates to check
34 * @return {Function} The combined predicate
35 * @see R.anyPass
36 * @example
37 *
38 * const isQueen = R.propEq('rank', 'Q');
39 * const isSpade = R.propEq('suit', '♠︎');
40 * const isQueenOfSpades = R.allPass([isQueen, isSpade]);
41 *
42 * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
43 * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true
44 */
45
46
47var allPass =
48/*#__PURE__*/
49_curry1(function allPass(preds) {
50 return curryN(reduce(max, 0, pluck('length', preds)), function () {
51 var idx = 0;
52 var len = preds.length;
53
54 while (idx < len) {
55 if (!preds[idx].apply(this, arguments)) {
56 return false;
57 }
58
59 idx += 1;
60 }
61
62 return true;
63 });
64});
65
66module.exports = allPass;
\No newline at end of file