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.3 KB
|
Line | |
---|
1 | var _curry3 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry3.js"); // `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.view, R.set, R.lens, R.lensIndex, R.lensProp, R.lensPath
|
---|
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; |
---|
Note:
See
TracBrowser
for help on using the repository browser.