You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

4 years ago
  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
  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. var anyPass =
  33. /*#__PURE__*/
  34. _curry1(function anyPass(preds) {
  35. return curryN(reduce(max, 0, pluck('length', preds)), function () {
  36. var idx = 0;
  37. var len = preds.length;
  38. while (idx < len) {
  39. if (preds[idx].apply(this, arguments)) {
  40. return true;
  41. }
  42. idx += 1;
  43. }
  44. return false;
  45. });
  46. });
  47. export default anyPass;