forked from ramda/ramda
/
mergeDeepWith.js
37 lines (35 loc) · 1.22 KB
/
mergeDeepWith.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import _curry3 from './internal/_curry3.js';
import mergeDeepWithKey from './mergeDeepWithKey.js';
/**
* Creates a new object with the own properties of the two provided objects.
* If a key exists in both objects:
* - and both associated values are also objects then the values will be
* recursively merged.
* - otherwise the provided function is applied to associated values using the
* resulting value as the new value associated with the key.
* If a key only exists in one object, the value will be associated with the key
* of the resulting object.
*
* @func
* @memberOf R
* @since v0.24.0
* @category Object
* @sig ((a, a) -> a) -> {a} -> {a} -> {a}
* @param {Function} fn
* @param {Object} lObj
* @param {Object} rObj
* @return {Object}
* @see R.mergeWith, R.mergeDeepWithKey
* @example
*
* R.mergeDeepWith(R.concat,
* { a: true, c: { values: [10, 20] }},
* { b: true, c: { values: [15, 35] }});
* //=> { a: true, b: true, c: { values: [10, 20, 15, 35] }}
*/
var mergeDeepWith = _curry3(function mergeDeepWith(fn, lObj, rObj) {
return mergeDeepWithKey(function(k, lVal, rVal) {
return fn(lVal, rVal);
}, lObj, rObj);
});
export default mergeDeepWith;