[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | /**
|
---|
| 7 | * Returns a "view" of the given data structure, determined by the given lens.
|
---|
| 8 | * The lens's focus determines which portion of the data structure is visible.
|
---|
| 9 | * Returns the defaultValue if "view" is null, undefined or NaN; otherwise the "view" is returned.
|
---|
| 10 | *
|
---|
| 11 | * @func viewOr
|
---|
| 12 | * @memberOf RA
|
---|
| 13 | * @since {@link https://char0n.github.io/ramda-adjunct/1.13.0|1.13.0}
|
---|
| 14 | * @category Object
|
---|
| 15 | * @typedef Lens s b = Functor f => (b -> f b) -> s -> f s
|
---|
| 16 | * @sig a -> Lens s b -> s -> b | a
|
---|
| 17 | * @see {@link http://ramdajs.com/docs/#view|R.view}
|
---|
| 18 | * @param {*} defaultValue The default value
|
---|
| 19 | * @param {Function} lens Van Laarhoven lens
|
---|
| 20 | * @param {*} data The data structure
|
---|
| 21 | * @returns {*} "view" or defaultValue
|
---|
| 22 | *
|
---|
| 23 | * @example
|
---|
| 24 | *
|
---|
| 25 | * RA.viewOr('N/A', R.lensProp('x'), {}); // => 'N/A'
|
---|
| 26 | * RA.viewOr('N/A', R.lensProp('x'), { x: 1 }); // => 1
|
---|
| 27 | * RA.viewOr('some', R.lensProp('y'), { y: null }); // => 'some'
|
---|
| 28 | * RA.viewOr('some', R.lensProp('y'), { y: false }); // => false
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | var viewOr = (0, _ramda.curryN)(3, function (defaultValue, lens, data) {
|
---|
| 32 | return (0, _ramda.defaultTo)(defaultValue, (0, _ramda.view)(lens, data));
|
---|
| 33 | });
|
---|
| 34 | var _default = viewOr;
|
---|
| 35 | exports["default"] = _default; |
---|