Skip to content
Permalink
Browse files

refactor: adopt list comprehensions to replace Enum.map to improve pe…

…rformance
  • Loading branch information
Maples7 committed Jun 18, 2019
1 parent cd4e29c commit 8de1abf59a18829e8e19a33a625f58424e577e3b
Showing with 13 additions and 5 deletions.
  1. +13 −5 lib/field_mask.ex
@@ -46,18 +46,26 @@ defmodule FieldMask do
["*"] ->
data
|> Map.keys()
|> Enum.map(&[&1, reveal(tree["*"], data[&1])])
|> Map.new(fn pair -> List.to_tuple(pair) end)
|> (fn keys ->
for key <- keys, into: %{} do
{key, reveal(tree["*"], data[key])}
end
end).()

keys ->
case data do
data when is_list(data) ->
Enum.map(data, &reveal(tree, &1))
for item <- data do
reveal(tree, item)
end

data when is_map(data) ->
keys
|> Enum.map(&[&1, reveal(tree[&1], data[&1])])
|> Map.new(fn pair -> List.to_tuple(pair) end)
|> (fn keys ->
for key <- keys, into: %{} do
{key, reveal(tree[key], data[key])}
end
end).()
end
end).()
end

0 comments on commit 8de1abf

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