Skip to content
Permalink
Browse files

refactor reveal as a single pipeline

  • Loading branch information
Maples7 committed Jun 14, 2019
1 parent 913be42 commit 3e610d80b69be0015e376273806df9711427e701
Showing with 29 additions and 29 deletions.
  1. +29 −29 lib/field_mask.ex
@@ -55,41 +55,41 @@ defmodule FieldMask do
{:error, "%ArgumentError{message: \"Wrong type for data: {%{\\\"c\\\" => 2, \\\"e\\\" => 1}, %{\\\"c\\\" => 4, \\\"f\\\" => 3}}\"}"}
"""
def reveal(tree, data) when is_map(tree) do
keys = Map.keys(tree)
tree
|> Map.keys()
|> (fn
[] ->
data

case keys do
[] ->
data
["*"] ->
cond do
is_list(data) ->
Enum.map(data, &reveal(tree["*"], &1))

["*"] ->
cond do
is_list(data) ->
Enum.map(data, &reveal(tree["*"], &1))
is_map(data) ->
data
|> Map.keys()
|> Enum.map(&[&1, reveal(tree["*"], data[&1])])
|> Map.new(fn pair -> List.to_tuple(pair) end)

is_map(data) ->
data
|> Map.keys()
|> Enum.map(&[&1, reveal(tree["*"], data[&1])])
|> Map.new(fn pair -> List.to_tuple(pair) end)

true ->
raise ArgumentError, message: "Wrong type for data: #{inspect(data)}"
end
true ->
raise ArgumentError, message: "Wrong type for data: #{inspect(data)}"
end

_ ->
cond do
is_list(data) ->
Enum.map(data, &reveal(tree, &1))
keys ->
cond do
is_list(data) ->
Enum.map(data, &reveal(tree, &1))

is_map(data) ->
keys
|> Enum.map(&[&1, reveal(tree[&1], data[&1])])
|> Map.new(fn pair -> List.to_tuple(pair) end)
is_map(data) ->
keys
|> Enum.map(&[&1, reveal(tree[&1], data[&1])])
|> Map.new(fn pair -> List.to_tuple(pair) end)

true ->
raise ArgumentError, message: "Wrong type for data: #{inspect(data)}"
end
end
true ->
raise ArgumentError, message: "Wrong type for data: #{inspect(data)}"
end
end).()
end

@doc ~S"""

0 comments on commit 3e610d8

Please sign in to comment.
You can’t perform that action at this time.