mirror of
https://github.com/swc-project/swc.git
synced 2024-12-30 17:15:11 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/lens.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
import map from './map.js';
|
|
|
|
|
|
/**
|
|
* Returns a lens for the given getter and setter functions. The getter "gets"
|
|
* the value of the focus; the setter "sets" the value of the focus. The setter
|
|
* should not mutate the data structure.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.8.0
|
|
* @category Object
|
|
* @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
|
|
* @sig (s -> a) -> ((a, s) -> s) -> Lens s a
|
|
* @param {Function} getter
|
|
* @param {Function} setter
|
|
* @return {Lens}
|
|
* @see R.view, R.set, R.over, R.lensIndex, R.lensProp
|
|
* @example
|
|
*
|
|
* const xLens = R.lens(R.prop('x'), R.assoc('x'));
|
|
*
|
|
* R.view(xLens, {x: 1, y: 2}); //=> 1
|
|
* R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
|
|
* R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
|
|
*/
|
|
var lens = _curry2(function lens(getter, setter) {
|
|
return function(toFunctorFn) {
|
|
return function(target) {
|
|
return map(
|
|
function(focus) {
|
|
return setter(focus, target);
|
|
},
|
|
toFunctorFn(getter(target))
|
|
);
|
|
};
|
|
};
|
|
});
|
|
export default lens;
|