main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
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 |
|
---|
29 | var all =
|
---|
30 | /*#__PURE__*/
|
---|
31 | _curry2(
|
---|
32 | /*#__PURE__*/
|
---|
33 | _dispatchable(['all'], _xall, function all(fn, list) {
|
---|
34 | var idx = 0;
|
---|
35 |
|
---|
36 | while (idx < list.length) {
|
---|
37 | if (!fn(list[idx])) {
|
---|
38 | return false;
|
---|
39 | }
|
---|
40 |
|
---|
41 | idx += 1;
|
---|
42 | }
|
---|
43 |
|
---|
44 | return true;
|
---|
45 | }));
|
---|
46 |
|
---|
47 | export default all; |
---|
Note:
See
TracBrowser
for help on using the repository browser.