Skip to content

Instantly share code, notes, and snippets.

@Lugghawk
Created July 6, 2016 18:52
Show Gist options
  • Save Lugghawk/f1069442c7cdc7226944de831803c327 to your computer and use it in GitHub Desktop.
Save Lugghawk/f1069442c7cdc7226944de831803c327 to your computer and use it in GitHub Desktop.
Map Merge
defmodule PMTest do
def apply_defaults(json_obj) do
Map.merge(json_obj, defaults, fn _,v1,v2 ->
case v1 do
nil -> v2
_ -> v1
end
end)
end
def defaults do
%{def1: "default_one", def2: "default_two", def3: "default_three"}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment