Skip to content

Instantly share code, notes, and snippets.

@alco
Created June 16, 2014 00:42
Show Gist options
  • Save alco/268fcf29a9c439b92fa9 to your computer and use it in GitHub Desktop.
Save alco/268fcf29a9c439b92fa9 to your computer and use it in GitHub Desktop.
spec = %{
commands: [
%{name: "abc", ...},
%{name: "def", ...},
...
]
}
...
# we have {key, val} defined
index = Enum.find_index(spec.commands, &(&1.name == key))
if !index, do: config_error("Unrecognized command: #{key}")
cmdspec = Enum.at(spec.commands, index)
Map.update!(spec, :commands, fn list ->
List.replace_at(list, index, Map.put(cmdspec, :action, val))
end)
index = Enum.find_index(spec.commands, &(&1.name == key))
if !index, do: config_error("Unrecognized command: #{key}")
put_in(spec.commands<[index]>[:action], val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment