GitHub

daffMerge

import { daffMerge } from '@daffodil/core'

Merges dictionaries with a specific strategy for handling collisions.

const daffMerge: __function

Examples

Merging two dictionaries with predefined mergers

const a = {
     ary: [1, 2],
  obj: {foo: 5, bar: 10}
}
const a = {
     ary: [3, 4],
  obj: {foo: 6},
  fish: 'tacos'
}
const result = daffMerge(
  [a, b],
  {
    ary: daffArrayConcatMerger,
    obj: daffDictAssignMerger
  }
)

the value of result would be:

{
  ary: [1, 2, 3, 4],
  obj: {foo: 6, bar: 10},
  fish: 'tacos'
}

Merging two dictionaries with predefined mergers

const a = {
     ary: [1, 2],
  obj: {foo: 5, bar: 10}
}
const a = {
     ary: [3, 4],
  obj: {foo: 6},
  fish: 'tacos'
}
const result = daffMerge(
  [a, b],
  {
    ary: daffArrayConcatMerger,
    obj: daffDictAssignMerger
  }
)

the value of result would be:

{
  ary: [1, 2, 3, 4],
  obj: {foo: 6, bar: 10},
  fish: 'tacos'
}