source: node_modules/ramda/src/mergeWithKey.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
Line 
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3.js");
4
5var _has =
6/*#__PURE__*/
7require("./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
35var 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
58module.exports = mergeWithKey;
Note: See TracBrowser for help on using the repository browser.