mergeDeepWith()

Like mergeDeep(), but when two non-collections or incompatible collections are encountered at the same key, it uses the merger function to determine the resulting value. Collections are considered incompatible if they fall into separate categories between keyed, indexed, and set-like.

mergeDeepWith<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.mergeDeepWith() which will also work with plain Objects and Arrays.

const { mergeDeepWith } = require('immutable') const original = { x: { y: 123 }} mergeDeepWith( (oldVal, newVal) => oldVal + newVal, original, { x: { y: 456 }} ) // { x: { y: 579 }} console.log(original) // { x: { y: 123 }}run it
This documentation is generated from immutable.d.ts. Pull requests and Issues welcome.