Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Last active September 7, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardarella/e23c7e7ce6760a5af0f8ff1efdd0e1b0 to your computer and use it in GitHub Desktop.
Save bcardarella/e23c7e7ce6760a5af0f8ff1efdd0e1b0 to your computer and use it in GitHub Desktop.
opts = [with: %{name: "George"}]
acc = %{
foo: %{
columns: %{
name: "Will"
}
}
}
with {:ok, override} <- Keyword.fetch(opts, :with),
{:ok, row} <- Map.fetch(acc, row_name),
{:ok, columns} <- Map.fetch(row, :columns) do
columns = Map.merge(columns, override)
put_in(acc, [row_name, :columns], columns)
else
:error -> acc
@chrismccord
Copy link

with {:ok, override} <- Keyword.fetch(opts, :with),
     %{} = cols <- get_in(acc, [row_name, :columns]),
     columns = Map.merge(cols, override) do

  put_in(acc, [row_name, :columns], columns)
else
  _ -> acc
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment