1 | import _curry1 from "./internal/_curry1.js";
|
---|
2 | import curryN from "./curryN.js";
|
---|
3 | import max from "./max.js";
|
---|
4 | import pluck from "./pluck.js";
|
---|
5 | import reduce from "./reduce.js";
|
---|
6 | /**
|
---|
7 | * Takes a list of predicates and returns a predicate that returns true for a
|
---|
8 | * given list of arguments if at least one of the provided predicates is
|
---|
9 | * satisfied by those arguments.
|
---|
10 | *
|
---|
11 | * The function returned is a curried function whose arity matches that of the
|
---|
12 | * highest-arity predicate.
|
---|
13 | *
|
---|
14 | * @func
|
---|
15 | * @memberOf R
|
---|
16 | * @since v0.9.0
|
---|
17 | * @category Logic
|
---|
18 | * @sig [(*... -> Boolean)] -> (*... -> Boolean)
|
---|
19 | * @param {Array} predicates An array of predicates to check
|
---|
20 | * @return {Function} The combined predicate
|
---|
21 | * @see R.allPass, R.either
|
---|
22 | * @example
|
---|
23 | *
|
---|
24 | * const isClub = R.propEq('♣', 'suit');
|
---|
25 | * const isSpade = R.propEq('♠', 'suit');
|
---|
26 | * const isBlackCard = R.anyPass([isClub, isSpade]);
|
---|
27 | *
|
---|
28 | * isBlackCard({rank: '10', suit: '♣'}); //=> true
|
---|
29 | * isBlackCard({rank: 'Q', suit: '♠'}); //=> true
|
---|
30 | * isBlackCard({rank: 'Q', suit: '♦'}); //=> false
|
---|
31 | */
|
---|
32 |
|
---|
33 | var anyPass =
|
---|
34 | /*#__PURE__*/
|
---|
35 | _curry1(function anyPass(preds) {
|
---|
36 | return curryN(reduce(max, 0, pluck('length', preds)), function () {
|
---|
37 | var idx = 0;
|
---|
38 | var len = preds.length;
|
---|
39 |
|
---|
40 | while (idx < len) {
|
---|
41 | if (preds[idx].apply(this, arguments)) {
|
---|
42 | return true;
|
---|
43 | }
|
---|
44 |
|
---|
45 | idx += 1;
|
---|
46 | }
|
---|
47 |
|
---|
48 | return false;
|
---|
49 | });
|
---|
50 | });
|
---|
51 |
|
---|
52 | export default anyPass; |
---|