source: node_modules/ramda/src/anyPass.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
RevLine 
[d24f17c]1var _curry1 =
2/*#__PURE__*/
3require("./internal/_curry1.js");
4
5var curryN =
6/*#__PURE__*/
7require("./curryN.js");
8
9var max =
10/*#__PURE__*/
11require("./max.js");
12
13var pluck =
14/*#__PURE__*/
15require("./pluck.js");
16
17var reduce =
18/*#__PURE__*/
19require("./reduce.js");
20/**
21 * Takes a list of predicates and returns a predicate that returns true for a
22 * given list of arguments if at least one of the provided predicates is
23 * satisfied 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.allPass, R.either
36 * @example
37 *
38 * const isClub = R.propEq('♣', 'suit');
39 * const isSpade = R.propEq('♠', 'suit');
40 * const isBlackCard = R.anyPass([isClub, isSpade]);
41 *
42 * isBlackCard({rank: '10', suit: '♣'}); //=> true
43 * isBlackCard({rank: 'Q', suit: '♠'}); //=> true
44 * isBlackCard({rank: 'Q', suit: '♦'}); //=> false
45 */
46
47
48var anyPass =
49/*#__PURE__*/
50_curry1(function anyPass(preds) {
51 return curryN(reduce(max, 0, pluck('length', preds)), function () {
52 var idx = 0;
53 var len = preds.length;
54
55 while (idx < len) {
56 if (preds[idx].apply(this, arguments)) {
57 return true;
58 }
59
60 idx += 1;
61 }
62
63 return false;
64 });
65});
66
67module.exports = anyPass;
Note: See TracBrowser for help on using the repository browser.