Created
May 28, 2019 05:48
-
-
Save opsb/70f5f21be184c26e4d1df1c433b22065 to your computer and use it in GitHub Desktop.
This file contains 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.Tree do | |
def transform_keys(map, transform) when is_map(map) do | |
Map.new( | |
Enum.map(map, fn {k, v} -> | |
{transform.(k) |> IO.inspect(label: "transformed"), transform_keys(v, transform)} | |
end) | |
) | |
end | |
def transform_keys(list, transform) when is_list(list) do | |
Enum.map(list, &transform_keys(&1, transform)) | |
end | |
def transform_keys(value, _transform) do | |
value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment