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