action-debian-package/node_modules/ramda/src/find.js
Dawid Dziurla 9308795b8b
update
2020-03-26 15:37:35 +01:00

55 lines
1.2 KiB
JavaScript

var _curry2 =
/*#__PURE__*/
require("./internal/_curry2");
var _dispatchable =
/*#__PURE__*/
require("./internal/_dispatchable");
var _xfind =
/*#__PURE__*/
require("./internal/_xfind");
/**
* Returns the first element of the list which matches the predicate, or
* `undefined` if no element matches.
*
* Dispatches to the `find` method of the second argument, if present.
*
* Acts as a transducer if a transformer is given in list position.
*
* @func
* @memberOf R
* @since v0.1.0
* @category List
* @sig (a -> Boolean) -> [a] -> a | undefined
* @param {Function} fn The predicate function used to determine if the element is the
* desired one.
* @param {Array} list The array to consider.
* @return {Object} The element found, or `undefined`.
* @see R.transduce
* @example
*
* const xs = [{a: 1}, {a: 2}, {a: 3}];
* R.find(R.propEq('a', 2))(xs); //=> {a: 2}
* R.find(R.propEq('a', 4))(xs); //=> undefined
*/
var find =
/*#__PURE__*/
_curry2(
/*#__PURE__*/
_dispatchable(['find'], _xfind, function find(fn, list) {
var idx = 0;
var len = list.length;
while (idx < len) {
if (fn(list[idx])) {
return list[idx];
}
idx += 1;
}
}));
module.exports = find;