merge-with

1.1.1 • Public • Published

Build Status

A port of clojure's merge-with.

Returns a map that consists of the rest of the maps transformed into the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with the mapping in the result by calling fn(val-in-result, val-in-latter).

function mergeWith(maps, fn) { }

Install

npm i -S merge-with

Usage

var assert = require('assert');
var mergeWith = require('merge-with');
 
var map = { a: 1 };
var map2 = { a: 2, b: 5 };
var map3 = { b: 3 };
var map4 = { c: 0, a: 1 };
 
function add(a, b) {
  return a + b;
}
 
var m = mergeWith(add, [map, map2, map3, map4]);
assert.equal(m.a, 4);
assert.equal(m.b, 8);
assert.equal(m.c, 0);

Package Sidebar

Install

npm i merge-with

Weekly Downloads

2

Version

1.1.1

License

ISC

Last publish

Collaborators

  • landau