UNPKG

888 BJavaScriptView Raw
1var _curry1 =
2/*#__PURE__*/
3require("./internal/_curry1");
4
5var lens =
6/*#__PURE__*/
7require("./lens");
8
9var nth =
10/*#__PURE__*/
11require("./nth");
12
13var update =
14/*#__PURE__*/
15require("./update");
16/**
17 * Returns a lens whose focus is the specified index.
18 *
19 * @func
20 * @memberOf R
21 * @since v0.14.0
22 * @category Object
23 * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
24 * @sig Number -> Lens s a
25 * @param {Number} n
26 * @return {Lens}
27 * @see R.view, R.set, R.over, R.nth
28 * @example
29 *
30 * const headLens = R.lensIndex(0);
31 *
32 * R.view(headLens, ['a', 'b', 'c']); //=> 'a'
33 * R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c']
34 * R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c']
35 */
36
37
38var lensIndex =
39/*#__PURE__*/
40_curry1(function lensIndex(n) {
41 return lens(nth(n), update(n));
42});
43
44module.exports = lensIndex;
\No newline at end of file