Created
February 5, 2017 20:06
-
-
Save dimitarvp/26551dfedbe53735efe3a07d521f2a49 to your computer and use it in GitHub Desktop.
Elixir function modifying a destination map only if a source map has a certain key whose value is processed and stored in the destination map.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Play do | |
def test1 do | |
src = %{createdAt: "2017-01-19T08:32:26+02:00"} | |
dest = %{} | |
dest = | |
case Map.has_key?(src, :createdAt) do | |
true -> | |
{:ok, date, _} = DateTime.from_iso8601(src[:createdAt]) | |
Map.put(dest, :createdAt, date) | |
false -> | |
dest | |
end | |
dest | |
end | |
end | |
Play.test1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @talentdeficit. Ended up slightly adapting a suggestion from Ben Wilson: https://www.irccloud.com/pastebin/mZJhLJLa/
EDIT: pasting in case the link stops working: