You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.0 KiB

4 years ago
  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. var update =
  27. /*#__PURE__*/
  28. _curry3(function update(idx, x, list) {
  29. return adjust(idx, always(x), list);
  30. });
  31. export default update;