1 | var _curry3 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry3"); // `Identity` is a functor that holds a single value, where `map` simply
|
4 | // transforms the held value with the provided function.
|
5 |
|
6 |
|
7 | var Identity = function (x) {
|
8 | return {
|
9 | value: x,
|
10 | map: function (f) {
|
11 | return Identity(f(x));
|
12 | }
|
13 | };
|
14 | };
|
15 | /**
|
16 | * Returns the result of "setting" the portion of the given data structure
|
17 | * focused by the given lens to the result of applying the given function to
|
18 | * the focused value.
|
19 | *
|
20 | * @func
|
21 | * @memberOf R
|
22 | * @since v0.16.0
|
23 | * @category Object
|
24 | * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
|
25 | * @sig Lens s a -> (a -> a) -> s -> s
|
26 | * @param {Lens} lens
|
27 | * @param {*} v
|
28 | * @param {*} x
|
29 | * @return {*}
|
30 | * @see R.prop, R.lensIndex, R.lensProp
|
31 | * @example
|
32 | *
|
33 | * const headLens = R.lensIndex(0);
|
34 | *
|
35 | * R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz']
|
36 | */
|
37 |
|
38 |
|
39 | var over =
|
40 | /*#__PURE__*/
|
41 | _curry3(function over(lens, f, x) {
|
42 | // The value returned by the getter function is first transformed with `f`,
|
43 | // then set as the value of an `Identity`. This is then mapped over with the
|
44 | // setter function of the lens.
|
45 | return lens(function (y) {
|
46 | return Identity(f(y));
|
47 | })(x).value;
|
48 | });
|
49 |
|
50 | module.exports = over; |
\ | No newline at end of file |