Skip to content

Instantly share code, notes, and snippets.

@arjan
Created July 28, 2016 09:20
Show Gist options
  • Save arjan/ef1afa1972f7e3dbd88b2364c7eea911 to your computer and use it in GitHub Desktop.
Save arjan/ef1afa1972f7e3dbd88b2364c7eea911 to your computer and use it in GitHub Desktop.
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