any.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import _curry2 from "./internal/_curry2.js";
  2. import _dispatchable from "./internal/_dispatchable.js";
  3. import _xany from "./internal/_xany.js";
  4. /**
  5. * Returns `true` if at least one of the elements of the list match the predicate,
  6. * `false` otherwise.
  7. *
  8. * Dispatches to the `any` 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 at least one element, `false`
  20. * otherwise.
  21. * @see R.all, R.none, R.transduce
  22. * @example
  23. *
  24. * const lessThan0 = R.flip(R.lt)(0);
  25. * const lessThan2 = R.flip(R.lt)(2);
  26. * R.any(lessThan0)([1, 2]); //=> false
  27. * R.any(lessThan2)([1, 2]); //=> true
  28. */
  29. var any =
  30. /*#__PURE__*/
  31. _curry2(
  32. /*#__PURE__*/
  33. _dispatchable(['any'], _xany, function any(fn, list) {
  34. var idx = 0;
  35. while (idx < list.length) {
  36. if (fn(list[idx])) {
  37. return true;
  38. }
  39. idx += 1;
  40. }
  41. return false;
  42. }));
  43. export default any;