source: node_modules/ramda/es/mergeDeepWithKey.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d24f17c]1import _curry3 from "./internal/_curry3.js";
2import _isObject from "./internal/_isObject.js";
3import mergeWithKey from "./mergeWithKey.js";
4/**
5 * Creates a new object with the own properties of the two provided objects.
6 * If a key exists in both objects:
7 * - and both associated values are also objects then the values will be
8 * recursively merged.
9 * - otherwise the provided function is applied to the key and associated values
10 * using the resulting value as the new value associated with the key.
11 * If a key only exists in one object, the value will be associated with the key
12 * of the resulting object.
13 *
14 * @func
15 * @memberOf R
16 * @since v0.24.0
17 * @category Object
18 * @sig ((String, a, a) -> a) -> {a} -> {a} -> {a}
19 * @param {Function} fn
20 * @param {Object} lObj
21 * @param {Object} rObj
22 * @return {Object}
23 * @see R.mergeWithKey, R.mergeDeepWith
24 * @example
25 *
26 * let concatValues = (k, l, r) => k == 'values' ? R.concat(l, r) : r
27 * R.mergeDeepWithKey(concatValues,
28 * { a: true, c: { thing: 'foo', values: [10, 20] }},
29 * { b: true, c: { thing: 'bar', values: [15, 35] }});
30 * //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }}
31 */
32
33var mergeDeepWithKey =
34/*#__PURE__*/
35_curry3(function mergeDeepWithKey(fn, lObj, rObj) {
36 return mergeWithKey(function (k, lVal, rVal) {
37 if (_isObject(lVal) && _isObject(rVal)) {
38 return mergeDeepWithKey(fn, lVal, rVal);
39 } else {
40 return fn(k, lVal, rVal);
41 }
42 }, lObj, rObj);
43});
44
45export default mergeDeepWithKey;
Note: See TracBrowser for help on using the repository browser.