UNPKG

953 BJavaScriptView Raw
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3");
4/**
5 * Makes a shallow clone of an object, setting or overriding the specified
6 * property with the given value. Note that this copies and flattens prototype
7 * properties onto the new object as well. All non-primitive properties are
8 * copied by reference.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.8.0
13 * @category Object
14 * @sig String -> a -> {k: v} -> {k: v}
15 * @param {String} 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
25
26var assoc =
27/*#__PURE__*/
28_curry3(function assoc(prop, val, obj) {
29 var result = {};
30
31 for (var p in obj) {
32 result[p] = obj[p];
33 }
34
35 result[prop] = val;
36 return result;
37});
38
39module.exports = assoc;
\No newline at end of file