UNPKG

1.24 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4
5var _dispatchable =
6/*#__PURE__*/
7require("./internal/_dispatchable");
8
9var _xany =
10/*#__PURE__*/
11require("./internal/_xany");
12/**
13 * Returns `true` if at least one of the elements of the list match the predicate,
14 * `false` otherwise.
15 *
16 * Dispatches to the `any` method of the second argument, if present.
17 *
18 * Acts as a transducer if a transformer is given in list position.
19 *
20 * @func
21 * @memberOf R
22 * @since v0.1.0
23 * @category List
24 * @sig (a -> Boolean) -> [a] -> Boolean
25 * @param {Function} fn The predicate function.
26 * @param {Array} list The array to consider.
27 * @return {Boolean} `true` if the predicate is satisfied by at least one element, `false`
28 * otherwise.
29 * @see R.all, R.none, R.transduce
30 * @example
31 *
32 * const lessThan0 = R.flip(R.lt)(0);
33 * const lessThan2 = R.flip(R.lt)(2);
34 * R.any(lessThan0)([1, 2]); //=> false
35 * R.any(lessThan2)([1, 2]); //=> true
36 */
37
38
39var any =
40/*#__PURE__*/
41_curry2(
42/*#__PURE__*/
43_dispatchable(['any'], _xany, function any(fn, list) {
44 var idx = 0;
45
46 while (idx < list.length) {
47 if (fn(list[idx])) {
48 return true;
49 }
50
51 idx += 1;
52 }
53
54 return false;
55}));
56
57module.exports = any;
\No newline at end of file