1 | var _curry3 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry3.js");
|
---|
4 |
|
---|
5 | var _has =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_has.js");
|
---|
8 | /**
|
---|
9 | * Creates a new object with the own properties of the two provided objects. If
|
---|
10 | * a key exists in both objects, the provided function is applied to the key
|
---|
11 | * and the values associated with the key in each object, with the result being
|
---|
12 | * used as the value associated with the key in the returned object.
|
---|
13 | *
|
---|
14 | * @func
|
---|
15 | * @memberOf R
|
---|
16 | * @since v0.19.0
|
---|
17 | * @category Object
|
---|
18 | * @sig ((String, a, a) -> a) -> {a} -> {a} -> {a}
|
---|
19 | * @param {Function} fn
|
---|
20 | * @param {Object} l
|
---|
21 | * @param {Object} r
|
---|
22 | * @return {Object}
|
---|
23 | * @see R.mergeDeepWithKey, R.merge, R.mergeWith
|
---|
24 | * @example
|
---|
25 | *
|
---|
26 | * let concatValues = (k, l, r) => k == 'values' ? R.concat(l, r) : r
|
---|
27 | * R.mergeWithKey(concatValues,
|
---|
28 | * { a: true, thing: 'foo', values: [10, 20] },
|
---|
29 | * { b: true, thing: 'bar', values: [15, 35] });
|
---|
30 | * //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] }
|
---|
31 | * @symb R.mergeWithKey(f, { x: 1, y: 2 }, { y: 5, z: 3 }) = { x: 1, y: f('y', 2, 5), z: 3 }
|
---|
32 | */
|
---|
33 |
|
---|
34 |
|
---|
35 | var mergeWithKey =
|
---|
36 | /*#__PURE__*/
|
---|
37 | _curry3(function mergeWithKey(fn, l, r) {
|
---|
38 | var result = {};
|
---|
39 | var k;
|
---|
40 | l = l || {};
|
---|
41 | r = r || {};
|
---|
42 |
|
---|
43 | for (k in l) {
|
---|
44 | if (_has(k, l)) {
|
---|
45 | result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | for (k in r) {
|
---|
50 | if (_has(k, r) && !_has(k, result)) {
|
---|
51 | result[k] = r[k];
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | return result;
|
---|
56 | });
|
---|
57 |
|
---|
58 | module.exports = mergeWithKey; |
---|