Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwinchester committed Aug 19, 2024
1 parent 3c8584d commit 2e808ae
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/data_mapper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ defmodule DataMapper do

# Applies a function to a field.
{from_key, {to_key, fun}}, acc when is_function(fun) ->
Map.put(acc, to_key, fun.(input[from_key]))
case input[from_key] do
nil -> acc
data -> Map.put(acc, to_key, fun.(data))
end

# Nested mapping.
{from_key, {to_key, sub_mapping}}, acc when is_map(sub_mapping) ->
Expand All @@ -77,6 +80,7 @@ defmodule DataMapper do

case input[from_key] do
data when is_list(data) -> Enum.map(data, &map(&1, sub_mapping, opts))
nil -> acc
data -> map(data, sub_mapping, opts)
end

Expand Down

0 comments on commit 2e808ae

Please sign in to comment.