UNPKG

1.08 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2"); // `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.prop, R.lensIndex, R.lensProp
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;
\No newline at end of file