source: node_modules/ramda/es/findLast.js

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 
1import _curry2 from "./internal/_curry2.js";
2import _dispatchable from "./internal/_dispatchable.js";
3import _xfindLast from "./internal/_xfindLast.js";
4/**
5 * Returns the last element of the list which matches the predicate, or
6 * `undefined` if no element matches.
7 *
8 * Acts as a transducer if a transformer is given in list position.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.1.1
13 * @category List
14 * @sig (a -> Boolean) -> [a] -> a | undefined
15 * @param {Function} fn The predicate function used to determine if the element is the
16 * desired one.
17 * @param {Array} list The array to consider.
18 * @return {Object} The element found, or `undefined`.
19 * @see R.transduce
20 * @example
21 *
22 * const xs = [{a: 1, b: 0}, {a:1, b: 1}];
23 * R.findLast(R.propEq(1, 'a'))(xs); //=> {a: 1, b: 1}
24 * R.findLast(R.propEq(4, 'a'))(xs); //=> undefined
25 */
26
27var findLast =
28/*#__PURE__*/
29_curry2(
30/*#__PURE__*/
31_dispatchable([], _xfindLast, function findLast(fn, list) {
32 var idx = list.length - 1;
33
34 while (idx >= 0) {
35 if (fn(list[idx])) {
36 return list[idx];
37 }
38
39 idx -= 1;
40 }
41}));
42
43export default findLast;
Note: See TracBrowser for help on using the repository browser.