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.2 KB
|
Line | |
---|
1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var _dispatchable =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_dispatchable.js");
|
---|
8 |
|
---|
9 | var _xfind =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./internal/_xfind.js");
|
---|
12 | /**
|
---|
13 | * Returns the first element of the list which matches the predicate, or
|
---|
14 | * `undefined` if no element matches.
|
---|
15 | *
|
---|
16 | * Dispatches to the `find` 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] -> a | undefined
|
---|
25 | * @param {Function} fn The predicate function used to determine if the element is the
|
---|
26 | * desired one.
|
---|
27 | * @param {Array} list The array to consider.
|
---|
28 | * @return {Object} The element found, or `undefined`.
|
---|
29 | * @see R.transduce
|
---|
30 | * @example
|
---|
31 | *
|
---|
32 | * const xs = [{a: 1}, {a: 2}, {a: 3}];
|
---|
33 | * R.find(R.propEq(2, 'a'))(xs); //=> {a: 2}
|
---|
34 | * R.find(R.propEq(4, 'a'))(xs); //=> undefined
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | var find =
|
---|
39 | /*#__PURE__*/
|
---|
40 | _curry2(
|
---|
41 | /*#__PURE__*/
|
---|
42 | _dispatchable(['find'], _xfind, function find(fn, list) {
|
---|
43 | var idx = 0;
|
---|
44 | var len = list.length;
|
---|
45 |
|
---|
46 | while (idx < len) {
|
---|
47 | if (fn(list[idx])) {
|
---|
48 | return list[idx];
|
---|
49 | }
|
---|
50 |
|
---|
51 | idx += 1;
|
---|
52 | }
|
---|
53 | }));
|
---|
54 |
|
---|
55 | module.exports = find; |
---|
Note:
See
TracBrowser
for help on using the repository browser.