Skip to content

Merging Logic

ServerlessSam edited this page Nov 10, 2022 · 19 revisions

Data files support 4 types:

  • String
  • Integer
  • List
  • Dictionary
  • NoneType

the following table summarises the behaivior:

→ Merging with | ↓ Merging into Str Int List Dict None
String default default default default No effect
Integer default Value becomes sum of the two ints default default No effect
List Append existing list with str Append existing list with int Elements of merging list are appended to original list Append existing list with dict No effect
Dictionary default default default Dictionaries are merged. Any conflicting keys will recursively merge their values No effect
NoneType Str becomes the value Int becomes the value List becomes the value Dict becomes the value No effect

Default Behaviour

The initial value is converted into a list (with the original value being at index 0) and the list is appended by the merging object.

Examples

A string merging into string

{
  "Original" : "foo", // The original string
  "Merging" : "bar", // The string to merge in
  "Result" : [
   "foo",
   "bar"
  ]
}

A dict merging into an integer

{
  "Original" : 123, // The original int
  "Merging" : {  // The dictionary to merge in
    "foo" : "bar"
  },
  "Result" : [
    123,
    {
     "foo" : "bar"
    }
  ]
}

Merging Into A String...

A String

See default behaviour

An Integer

See default behaviour

A List

See default behaviour

A Dictionary

See default behaviour

A NoneType

No effect.

Merging Into An Integer...

A String

See default behaviour

An Integer

The resulting integer is the sum of the orginal and merging integers.

{
  "Original" : 10,  // The original int
  "Merging" : 5,  // The int to merge in
  "Result" : 15
}

A List

See default behaviour

A Dictionary

See default behaviour

A NoneType

No effect.

Merging Into A List...

Anything

Merging anything except another List or NoneType into a list will simply append the list with the value being merged in.

{
  "Original" : [  // The original list
    "foo",
    "bar"
  ],
  "Merging" : "hello, world!", // The string to merge in
  "Result" : [
    "foo",
    "bar",
    "hello, world!"
  ]
}

Merging in another list instead appends the original list with each element of the list being merged in.

{
  "Original" : [  // The original list
    "foo",
    "bar"
  ],
  "Merging" : [  // The list to merge in
    "hello",
    "world"
  ],
  "Result" : [
    "foo",
    "bar",
    "hello",
    "world"
  ]
}

Merging in NoneType will have no effect. The list will not change.

Merging Into A Dictionary...

A String

See default behaviour

An Integer

See default behaviour

A List

See default behaviour

A Dictionary

Dictionaries are combined. Any conflicting keys will recursively merge the values of those keys using the same dfm merging logic.

{
  "Original" : {  // Original dict
    "foo" : "bar"
  },
  "Merging" : {  // Dict to merge in
    "hello" : "world"
  },
  "Result" : {
    "foo" : "bar",
    "hello" : "world"
  }
}

A NoneType

No effect

Merging Into A NoneType...

Anything

Merging anything into a NoneType will simply set the merging object as the new value.

{
  "Original" : null,  // Original value is null
  "Merging" : {  // Dict to merge in
    "foo" : "bar"
  },
  "Result" : {  // Result is simply the dict being merged in
    "foo" : "bar"
  },
}