deep_merge v0.2.0 DeepMerge.Resolver protocol View Source
Protocol defining how conflicts during deep_merge should be resolved.
As part of the DeepMerge library this protocol is already implemented for
Map
and List
as well as a fallback to Any
.
Link to this section Summary
Functions
Defines what happens when a merge conflict occurs on this data type during a deep_merge
Link to this section Types
Link to this section Functions
Defines what happens when a merge conflict occurs on this data type during a deep_merge.
Can be implemented for additional data types to implement custom deep merging behavior.
The passed in values are:
original
- the value in the original data structure, usually left side argumentoverride
- the value with whichoriginal
would be overridden in a normalmerge/2
resolver
- the function used by DeepMerge to resolve merge conflicts, i.e. what you can pass toMap.merge/3
andKeyword.merge/3
to continue deeply merging.
An example implementation might look like this if you want to deeply merge your struct if the other value also is a struct:
defmodule MyStruct do
defstruct [:attrs]
end
defimpl DeepMerge.Resolver, for: MyStruct do
def resolve(original, override = %{__struct__: MyStruct}, resolver) do
Map.merge(original, override, resolver)
end
def resolve(_, override, _) do
override
end
end