mergeWith()
Returns a copy of the collection with the remaining collections merged in, calling the merger
function whenever an existing value is encountered.
mergeWith<C>(merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,collection: C,...collections: Array<Iterable<unknown> | Iterable<[unknown, unknown]> | {[key: string]: unknown}>): C
Discussion
A functional alternative to collection.mergeWith()
which will also work with plain Objects and Arrays.
const { mergeWith } = require('immutable') const original = { x: 123, y: 456 } mergeWith( (oldVal, newVal) => oldVal + newVal, original, { y: 789, z: 'abc' } ) // { x: 123, y: 1245, z: 'abc' } console.log(original) // { x: 123, y: 456 }run it
© 2014–present, Lee Byron and other contributors
Licensed under the 3-clause BSD License.
https://immutable-js.com/docs/v4.0.0/mergeWith()/