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.

50 lines
1.3 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 every one of the provided predicates is satisfied
  9. * 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.anyPass
  22. * @example
  23. *
  24. * const isQueen = R.propEq('rank', 'Q');
  25. * const isSpade = R.propEq('suit', '♠︎');
  26. * const isQueenOfSpades = R.allPass([isQueen, isSpade]);
  27. *
  28. * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
  29. * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true
  30. */
  31. var allPass =
  32. /*#__PURE__*/
  33. _curry1(function allPass(preds) {
  34. return curryN(reduce(max, 0, pluck('length', preds)), function () {
  35. var idx = 0;
  36. var len = preds.length;
  37. while (idx < len) {
  38. if (!preds[idx].apply(this, arguments)) {
  39. return false;
  40. }
  41. idx += 1;
  42. }
  43. return true;
  44. });
  45. });
  46. export default allPass;