Skip to content

Instantly share code, notes, and snippets.

@rugyoga
Created September 4, 2022 22:26
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 rugyoga/7e06986ea10db0fb7a82f6815780d2bf to your computer and use it in GitHub Desktop.
Save rugyoga/7e06986ea10db0fb7a82f6815780d2bf to your computer and use it in GitHub Desktop.
Take the delta of two simple velues
@spec delta_simple(path(), term(), term()) :: [delta()]
defp delta_simple(_path, a, b) when a == b, do: []
defp delta_simple(path, a, b) do
cond do
empty?(a) -> [{path, {:add, b}}]
empty?(b) -> [{path, {:delete, a}}]
true -> [{path, {:update, a, b}}]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment