1 | var _curry3 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry3");
|
4 |
|
5 | var _isObject =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_isObject");
|
8 |
|
9 | var mergeWithKey =
|
10 | /*#__PURE__*/
|
11 | require("./mergeWithKey");
|
12 | /**
|
13 | * Creates a new object with the own properties of the two provided objects.
|
14 | * If a key exists in both objects:
|
15 | * - and both associated values are also objects then the values will be
|
16 | * recursively merged.
|
17 | * - otherwise the provided function is applied to the key and associated values
|
18 | * using the resulting value as the new value associated with the key.
|
19 | * If a key only exists in one object, the value will be associated with the key
|
20 | * of the resulting object.
|
21 | *
|
22 | * @func
|
23 | * @memberOf R
|
24 | * @since v0.24.0
|
25 | * @category Object
|
26 | * @sig ((String, a, a) -> a) -> {a} -> {a} -> {a}
|
27 | * @param {Function} fn
|
28 | * @param {Object} lObj
|
29 | * @param {Object} rObj
|
30 | * @return {Object}
|
31 | * @see R.mergeWithKey, R.mergeDeepWith
|
32 | * @example
|
33 | *
|
34 | * let concatValues = (k, l, r) => k == 'values' ? R.concat(l, r) : r
|
35 | * R.mergeDeepWithKey(concatValues,
|
36 | * { a: true, c: { thing: 'foo', values: [10, 20] }},
|
37 | * { b: true, c: { thing: 'bar', values: [15, 35] }});
|
38 | * //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }}
|
39 | */
|
40 |
|
41 |
|
42 | var mergeDeepWithKey =
|
43 | /*#__PURE__*/
|
44 | _curry3(function mergeDeepWithKey(fn, lObj, rObj) {
|
45 | return mergeWithKey(function (k, lVal, rVal) {
|
46 | if (_isObject(lVal) && _isObject(rVal)) {
|
47 | return mergeDeepWithKey(fn, lVal, rVal);
|
48 | } else {
|
49 | return fn(k, lVal, rVal);
|
50 | }
|
51 | }, lObj, rObj);
|
52 | });
|
53 |
|
54 | module.exports = mergeDeepWithKey; |
\ | No newline at end of file |