UNPKG

1.08 kBJavaScriptView Raw
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3");
4
5var adjust =
6/*#__PURE__*/
7require("./adjust");
8
9var always =
10/*#__PURE__*/
11require("./always");
12/**
13 * Returns a new copy of the array with the element at the provided index
14 * replaced with the given value.
15 *
16 * @func
17 * @memberOf R
18 * @since v0.14.0
19 * @category List
20 * @sig Number -> a -> [a] -> [a]
21 * @param {Number} idx The index to update.
22 * @param {*} x The value to exist at the given index of the returned array.
23 * @param {Array|Arguments} list The source array-like object to be updated.
24 * @return {Array} A copy of `list` with the value at index `idx` replaced with `x`.
25 * @see R.adjust
26 * @example
27 *
28 * R.update(1, '_', ['a', 'b', 'c']); //=> ['a', '_', 'c']
29 * R.update(-1, '_', ['a', 'b', 'c']); //=> ['a', 'b', '_']
30 * @symb R.update(-1, a, [b, c]) = [b, a]
31 * @symb R.update(0, a, [b, c]) = [a, c]
32 * @symb R.update(1, a, [b, c]) = [b, a]
33 */
34
35
36var update =
37/*#__PURE__*/
38_curry3(function update(idx, x, list) {
39 return adjust(idx, always(x), list);
40});
41
42module.exports = update;
\No newline at end of file