Skip to content

Instantly share code, notes, and snippets.

@chasers
Created April 11, 2019 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chasers/603ac0eaa6b1c25ceaa617f6a65f8587 to your computer and use it in GitHub Desktop.
Save chasers/603ac0eaa6b1c25ceaa617f6a65f8587 to your computer and use it in GitHub Desktop.
Deep Merge Test
defmodule Logflare.DeepMergeTest do
# this works: DeepMerge.deep_merge(%{a: %{b: 1}, c: [d: 1]}, %{a: %{z: 5}, c: [x: 0]})
def merge() do
DeepMerge.deep_merge(newschema().fields, oldschema().fields)
end
def newschema do
%{
fields: [
%{a: "one", fields: nil},
%{b: "two", fields: nil},
%{
c: "three",
fields: [
%{aa: "one one", fields: nil},
%{bb: "two two", fields: nil},
%{
cc: "three, three",
fields: [
%{aaa: "one one one", fields: nil}
]
},
%{dd: "four four", fields: nil}
]
}
]
}
end
def oldschema do
%{
fields: [
%{a: "one", fields: nil},
%{
c: "three",
fields: [
%{aa: "one one", fields: nil},
%{bb: "two two", fields: nil},
%{
cc: "three, three",
fields: [
%{aaa: "one one one", fields: nil},
%{bbb: "two two two", fields: nil},
%{ccc: "three three three", fields: nil}
]
}
]
}
]
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment