source: node_modules/ramda/es/lensPath.js

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: 997 bytes
RevLine 
[d24f17c]1import _curry1 from "./internal/_curry1.js";
2import assocPath from "./assocPath.js";
3import lens from "./lens.js";
4import path from "./path.js";
5/**
6 * Returns a lens whose focus is the specified path.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.19.0
11 * @category Object
12 * @typedefn Idx = String | Int | Symbol
13 * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
14 * @sig [Idx] -> Lens s a
15 * @param {Array} path The path to use.
16 * @return {Lens}
17 * @see R.view, R.set, R.over
18 * @example
19 *
20 * const xHeadYLens = R.lensPath(['x', 0, 'y']);
21 *
22 * R.view(xHeadYLens, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
23 * //=> 2
24 * R.set(xHeadYLens, 1, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
25 * //=> {x: [{y: 1, z: 3}, {y: 4, z: 5}]}
26 * R.over(xHeadYLens, R.negate, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
27 * //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]}
28 */
29
30var lensPath =
31/*#__PURE__*/
32_curry1(function lensPath(p) {
33 return lens(path(p), assocPath(p));
34});
35
36export default lensPath;
Note: See TracBrowser for help on using the repository browser.