source: node_modules/ramda/es/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.4 KB
Line 
1import _curry1 from "./internal/_curry1.js";
2import curryN from "./curryN.js";
3import max from "./max.js";
4import pluck from "./pluck.js";
5import 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
33var 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
52export default anyPass;
Note: See TracBrowser for help on using the repository browser.