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.2 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry3 from "./internal/_curry3.js"; // `Identity` is a functor that holds a single value, where `map` simply
|
---|
| 2 | // transforms the held value with the provided function.
|
---|
| 3 |
|
---|
| 4 | var Identity = function (x) {
|
---|
| 5 | return {
|
---|
| 6 | value: x,
|
---|
| 7 | map: function (f) {
|
---|
| 8 | return Identity(f(x));
|
---|
| 9 | }
|
---|
| 10 | };
|
---|
| 11 | };
|
---|
| 12 | /**
|
---|
| 13 | * Returns the result of "setting" the portion of the given data structure
|
---|
| 14 | * focused by the given lens to the result of applying the given function to
|
---|
| 15 | * the focused value.
|
---|
| 16 | *
|
---|
| 17 | * @func
|
---|
| 18 | * @memberOf R
|
---|
| 19 | * @since v0.16.0
|
---|
| 20 | * @category Object
|
---|
| 21 | * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
|
---|
| 22 | * @sig Lens s a -> (a -> a) -> s -> s
|
---|
| 23 | * @param {Lens} lens
|
---|
| 24 | * @param {*} v
|
---|
| 25 | * @param {*} x
|
---|
| 26 | * @return {*}
|
---|
| 27 | * @see R.view, R.set, R.lens, R.lensIndex, R.lensProp, R.lensPath
|
---|
| 28 | * @example
|
---|
| 29 | *
|
---|
| 30 | * const headLens = R.lensIndex(0);
|
---|
| 31 | *
|
---|
| 32 | * R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz']
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | var over =
|
---|
| 37 | /*#__PURE__*/
|
---|
| 38 | _curry3(function over(lens, f, x) {
|
---|
| 39 | // The value returned by the getter function is first transformed with `f`,
|
---|
| 40 | // then set as the value of an `Identity`. This is then mapped over with the
|
---|
| 41 | // setter function of the lens.
|
---|
| 42 | return lens(function (y) {
|
---|
| 43 | return Identity(f(y));
|
---|
| 44 | })(x).value;
|
---|
| 45 | });
|
---|
| 46 |
|
---|
| 47 | export default over; |
---|
Note:
See
TracBrowser
for help on using the repository browser.