diff --git a/lib/data_mapper.ex b/lib/data_mapper.ex index 8328bab..56faf86 100644 --- a/lib/data_mapper.ex +++ b/lib/data_mapper.ex @@ -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) -> @@ -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 diff --git a/mix.exs b/mix.exs index c8b643c..4dec1a9 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule DataMapper.MixProject do def project do [ app: :data_mapper, - version: "0.2.0", + version: "0.2.1", elixir: "~> 1.9", start_permanent: Mix.env() == :prod, deps: deps(),