source: node_modules/ramda-adjunct/lib/viewOr.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.2 KB
RevLine 
[d24f17c]1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _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
31var viewOr = (0, _ramda.curryN)(3, function (defaultValue, lens, data) {
32 return (0, _ramda.defaultTo)(defaultValue, (0, _ramda.view)(lens, data));
33});
34var _default = viewOr;
35exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.