Created
July 28, 2016 09:20
-
-
Save arjan/ef1afa1972f7e3dbd88b2364c7eea911 to your computer and use it in GitHub Desktop.
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 Util do | |
def clean_struct(input = %{__struct__: _}) do | |
input | |
|> Map.delete(:__struct__) | |
|> clean_struct | |
end | |
def clean_struct(input = %{}) do | |
input | |
|> Enum.map(fn({k, v}) -> {k, &clean_struct/1} end) | |
|> Enum.into(%{}) | |
end | |
def clean_struct(input) when is_list(input) do | |
input | |
|> Enum.map(&clean_struct/1) | |
end | |
def clean_struct(input), do: input | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment