Update Map Syntax
There is a special syntax for updating a map in elixir.
thing = %{a: 1, b: 2, c: 3}
updated_thing = %{thing | b: 4}
# %{a: 1, b: 4, c: 3}
But be careful, it throws an error if you try to update a key that doesn't exist!!
thing = %{a: 1, b: 2, c: 3}
# ** (KeyError) key :x not found in: %{a: 1, b: 2, c: 3}
Tweet