[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var map =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./map.js");
|
---|
| 8 | /**
|
---|
| 9 | * Returns a lens for the given getter and setter functions. The getter "gets"
|
---|
| 10 | * the value of the focus; the setter "sets" the value of the focus. The setter
|
---|
| 11 | * should not mutate the data structure.
|
---|
| 12 | *
|
---|
| 13 | * @func
|
---|
| 14 | * @memberOf R
|
---|
| 15 | * @since v0.8.0
|
---|
| 16 | * @category Object
|
---|
| 17 | * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
|
---|
| 18 | * @sig (s -> a) -> ((a, s) -> s) -> Lens s a
|
---|
| 19 | * @param {Function} getter
|
---|
| 20 | * @param {Function} setter
|
---|
| 21 | * @return {Lens}
|
---|
| 22 | * @see R.view, R.set, R.over, R.lensIndex, R.lensProp
|
---|
| 23 | * @example
|
---|
| 24 | *
|
---|
| 25 | * const xLens = R.lens(R.prop('x'), R.assoc('x'));
|
---|
| 26 | *
|
---|
| 27 | * R.view(xLens, {x: 1, y: 2}); //=> 1
|
---|
| 28 | * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
|
---|
| 29 | * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | var lens =
|
---|
| 34 | /*#__PURE__*/
|
---|
| 35 | _curry2(function lens(getter, setter) {
|
---|
| 36 | return function (toFunctorFn) {
|
---|
| 37 | return function (target) {
|
---|
| 38 | return map(function (focus) {
|
---|
| 39 | return setter(focus, target);
|
---|
| 40 | }, toFunctorFn(getter(target)));
|
---|
| 41 | };
|
---|
| 42 | };
|
---|
| 43 | });
|
---|
| 44 |
|
---|
| 45 | module.exports = lens; |
---|