ramda
Version:
A practical functional library for JavaScript programmers.
34 lines • 1.11 kB
JavaScript
var _curry1 = /*#__PURE__*/require("./internal/_curry1.js");
var assocPath = /*#__PURE__*/require("./assocPath.js");
var lens = /*#__PURE__*/require("./lens.js");
var _path = /*#__PURE__*/require("./internal/_path.js");
/**
* Returns a lens whose focus is the specified path.
*
* @func
* @memberOf R
* @since v0.19.0
* @category Object
* @typedefn Idx = String | Int | Symbol
* @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
* @sig [Idx] -> Lens s a
* @param {Array} path The path to use.
* @return {Lens}
* @see R.view, R.set, R.over
* @example
*
* const xHeadYLens = R.lensPath(['x', 0, 'y']);
*
* R.view(xHeadYLens, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
* //=> 2
* R.set(xHeadYLens, 1, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
* //=> {x: [{y: 1, z: 3}, {y: 4, z: 5}]}
* R.over(xHeadYLens, R.negate, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
* //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]}
*/
var lensPath = /*#__PURE__*/_curry1(function lensPath(p) {
return lens(function (val) {
return _path(p, val);
}, assocPath(p));
});
module.exports = lensPath;