UNPKG

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