[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | /**
|
---|
| 7 | * Returns the first element of the list which matches the predicate.
|
---|
| 8 | * Returns default value if no element matches or matched element is `null`, `undefined` or `NaN`.
|
---|
| 9 | * Dispatches to the find method of the second argument, if present.
|
---|
| 10 | * Acts as a transducer if a transformer is given in list position.
|
---|
| 11 | *
|
---|
| 12 | * @func findOr
|
---|
| 13 | * @memberOf RA
|
---|
| 14 | * @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
|
---|
| 15 | * @category List
|
---|
| 16 | * @sig a -> (b -> Boolean) -> [b] -> b | a
|
---|
| 17 | * @param {*} defaultValue The default value
|
---|
| 18 | * @param {Function} fn The predicate function used to determine if the element is the desired one.
|
---|
| 19 | * @param {Array} list The array to consider.
|
---|
| 20 | * @return {*} The element found, or the default value.
|
---|
| 21 | * @see {@link http://ramdajs.com/docs/#defaultTo|R.defaultTo}, {@link http://ramdajs.com/docs/#find|R.find}
|
---|
| 22 | * @example
|
---|
| 23 | *
|
---|
| 24 | * RA.findOr(1, isUndefined, [1, 2, undefined]); // => 1
|
---|
| 25 | * RA.findOr(1, val => val === 2, [1, 2, undefined]); // => 2
|
---|
| 26 | * RA.findOr(1, val => val === 3, [1, 2, undefined]); // => 1
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | var findOr = (0, _ramda.curry)(function (defaultVal, fn, list) {
|
---|
| 30 | return (0, _ramda.pipe)((0, _ramda.find)(fn), (0, _ramda.defaultTo)(defaultVal))(list);
|
---|
| 31 | });
|
---|
| 32 | var _default = findOr;
|
---|
| 33 | exports["default"] = _default; |
---|