I need to convert in place in a map some values only of they exist. The key can be either binary or atom.
Is there a more Elixir way to do it than my solution below?
defp convert_time_params(params) do
params
|> (fn x ->
if Map.has_key?(x, "start_time"), do: update_in(x, ["start_time"], &CalendarUtils.from_iso8601/1), else: x
end).()
|> (fn x ->
if Map.has_key?(x, :start_time),
do: update_in(x, [Access.key!(:start_time)], &CalendarUtils.from_iso8601/1),
else: x
end).()
|> (fn x ->
if Map.has_key?(x, "end_time"), do: update_in(x, ["end_time"], &CalendarUtils.from_iso8601/1), else: x
end).()
|> (fn x ->
if Map.has_key?(x, :end_time),
do: update_in(x, [Access.key!(:end_time)], &CalendarUtils.from_iso8601/1),
else: x
end).()
end
The map is used in Ecto so I can not change the key type from atom to binary. I need to keep the input the same






















