Skip to content

Commit

Permalink
Use Enum.into/3.
Browse files Browse the repository at this point in the history
Enum.into/3 lets you transform the input values, so this avoids a
second loop.
  • Loading branch information
asummers committed Feb 3, 2017
1 parent fab5b57 commit 76485c3
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/stripe/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ defmodule Stripe.Util do
}
"""
def map_keys_to_atoms(m) do
Enum.map(m, fn
Enum.into(m, %{}, fn
{k, v} when is_binary(k) ->
a = String.to_existing_atom(k)
{a, v}
entry ->
entry
end)
|> Enum.into(%{})
end

def string_map_to_atoms([string_key_map]) do
Expand All @@ -48,9 +47,7 @@ defmodule Stripe.Util do
end

def atomize_keys(map = %{}) do
map
|> Enum.map(fn {k, v} -> {atomize_key(k), atomize_keys(v)} end)
|> Enum.into(%{})
Enum.into(map, %{}, fn {k, v} -> {atomize_key(k), atomize_keys(v)} end)
end
def atomize_keys([head | rest]), do: [atomize_keys(head) | atomize_keys(rest)]
# Default
Expand Down

0 comments on commit 76485c3

Please sign in to comment.