source: node_modules/ramda/src/view.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js"); // `Const` is a functor that effectively ignores the function given to `map`.
4
5
6var Const = function (x) {
7 return {
8 value: x,
9 'fantasy-land/map': function () {
10 return this;
11 }
12 };
13};
14/**
15 * Returns a "view" of the given data structure, determined by the given lens.
16 * The lens's focus determines which portion of the data structure is visible.
17 *
18 * @func
19 * @memberOf R
20 * @since v0.16.0
21 * @category Object
22 * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
23 * @sig Lens s a -> s -> a
24 * @param {Lens} lens
25 * @param {*} x
26 * @return {*}
27 * @see R.set, R.over, R.lens, R.lensIndex, R.lensProp, R.lensPath
28 * @example
29 *
30 * const xLens = R.lensProp('x');
31 *
32 * R.view(xLens, {x: 1, y: 2}); //=> 1
33 * R.view(xLens, {x: 4, y: 2}); //=> 4
34 */
35
36
37var view =
38/*#__PURE__*/
39_curry2(function view(lens, x) {
40 // Using `Const` effectively ignores the setter function of the `lens`,
41 // leaving the value returned by the getter function unmodified.
42 return lens(Const)(x).value;
43});
44
45module.exports = view;
Note: See TracBrowser for help on using the repository browser.