Skip to content

Instantly share code, notes, and snippets.

View noelworden's full-sized avatar

Noel Worden noelworden

View GitHub Profile
def get_message(error) do
converted_opts = Enum.map(error.opts, fn {key, value} ->
{String.to_existing_atom(key), value}
end)
translate_error({"#{error.message}", converted_opts})
end
def create!(attrs) do
%{attrs | message_opts: Map.new(attrs.message_opts)}
|> SourceFileError.changeset()
|> Repo.insert!()
end
%{example_map | key: updated_value}
iex> example_map = %{alpha: "one", bravo: "two", charlie: "three"}
%{alpha: "one", bravo: "two", charlie: "three"}
iex> %{example_map | charlie: "four"}
%{alpha: "one", bravo: "two", charlie: "four"}
iex> %{example_map | delta: "five"}
** (KeyError) key :delta not found in: %{alpha: "one", bravo: "two", charlie: "three"}
(stdlib 3.12.1) :maps.update(:delta, "five", %{alpha: "one", bravo: "two", charlie: "three"})
(stdlib 3.12.1) erl_eval.erl:256: anonymous fn/2 in :erl_eval.expr/5
(stdlib 3.12.1) lists.erl:1263: :lists.foldl/3
Map.put/3
Map.replace!/3
Map.update!/3
Map.update/4
@noelworden
noelworden / week_july6_map_put.ex
Last active July 17, 2020 23:37
#blog_snippets
iex> Map.put(example_map, :charlie, "four")
%{alpha: "one", bravo: "two", charlie: "four"}
iex> Map.put(example_map, :delta, "five")
%{alpha: "one", bravo: "two", charlie: "three", delta: "five"}
iex> Map.replace!(example_map, :charlie, "four")
%{alpha: "one", bravo: "two", charlie: "four"}