all.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import _curry2 from "./internal/_curry2.js";
  2. import _dispatchable from "./internal/_dispatchable.js";
  3. import _xall from "./internal/_xall.js";
  4. /**
  5. * Returns `true` if all elements of the list match the predicate, `false` if
  6. * there are any that don't.
  7. *
  8. * Dispatches to the `all` method of the second argument, if present.
  9. *
  10. * Acts as a transducer if a transformer is given in list position.
  11. *
  12. * @func
  13. * @memberOf R
  14. * @since v0.1.0
  15. * @category List
  16. * @sig (a -> Boolean) -> [a] -> Boolean
  17. * @param {Function} fn The predicate function.
  18. * @param {Array} list The array to consider.
  19. * @return {Boolean} `true` if the predicate is satisfied by every element, `false`
  20. * otherwise.
  21. * @see R.any, R.none, R.transduce
  22. * @example
  23. *
  24. * const equals3 = R.equals(3);
  25. * R.all(equals3)([3, 3, 3, 3]); //=> true
  26. * R.all(equals3)([3, 3, 1, 3]); //=> false
  27. */
  28. var all =
  29. /*#__PURE__*/
  30. _curry2(
  31. /*#__PURE__*/
  32. _dispatchable(['all'], _xall, function all(fn, list) {
  33. var idx = 0;
  34. while (idx < list.length) {
  35. if (!fn(list[idx])) {
  36. return false;
  37. }
  38. idx += 1;
  39. }
  40. return true;
  41. }));
  42. export default all;