Skip to content

Commit 2e808ae

Browse files
Fix some issues
1 parent 3c8584d commit 2e808ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/data_mapper.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ defmodule DataMapper do
6565

6666
# Applies a function to a field.
6767
{from_key, {to_key, fun}}, acc when is_function(fun) ->
68-
Map.put(acc, to_key, fun.(input[from_key]))
68+
case input[from_key] do
69+
nil -> acc
70+
data -> Map.put(acc, to_key, fun.(data))
71+
end
6972

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

7881
case input[from_key] do
7982
data when is_list(data) -> Enum.map(data, &map(&1, sub_mapping, opts))
83+
nil -> acc
8084
data -> map(data, sub_mapping, opts)
8185
end
8286

0 commit comments

Comments
 (0)