Last active
September 22, 2022 14:08
-
-
Save mpugach/a04bf0ee6962b8edab43933e9075c577 to your computer and use it in GitHub Desktop.
Elixir deep compare hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DeepCompare do | |
def call(payload_a, payload_b) when is_map(payload_a) and is_map(payload_b) do | |
Enum.reduce(payload_a, true, fn {k, v}, acc -> | |
acc and call(v, payload_b[k]) | |
end) | |
end | |
def call([element_a | rest_of_a], [element_b | rest_of_b]) do | |
call(element_a, element_b) and call(rest_of_a, rest_of_b) | |
end | |
def call(payload_a, payload_b) do | |
result = payload_a === payload_b | |
unless result, do: IO.inspect({payload_a, payload_b}, label: "Difference") | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment