-
Notifications
You must be signed in to change notification settings - Fork 1
Merging Logic
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 |
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.
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"
}
]
}
No effect.
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
}
No effect.
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.
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"
}
}
No effect
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"
},
}