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