assoc.js 939 B

12345678910111213141516171819202122232425262728293031
  1. import _curry3 from "./internal/_curry3.js";
  2. import assocPath from "./assocPath.js";
  3. /**
  4. * Makes a shallow clone of an object, setting or overriding the specified
  5. * property with the given value. Note that this copies and flattens prototype
  6. * properties onto the new object as well. All non-primitive properties are
  7. * copied by reference.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.8.0
  12. * @category Object
  13. * @typedefn Idx = String | Int
  14. * @sig Idx -> a -> {k: v} -> {k: v}
  15. * @param {String|Number} prop The property name to set
  16. * @param {*} val The new value
  17. * @param {Object} obj The object to clone
  18. * @return {Object} A new object equivalent to the original except for the changed property.
  19. * @see R.dissoc, R.pick
  20. * @example
  21. *
  22. * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
  23. */
  24. var assoc =
  25. /*#__PURE__*/
  26. _curry3(function assoc(prop, val, obj) {
  27. return assocPath([prop], val, obj);
  28. });
  29. export default assoc;