Keyword.get_and_update-exclamation-mark
You're seeing just the function
get_and_update-exclamation-mark
, go back to Keyword module for more information.
Specs
get_and_update!( t(), key(), (value() | nil -> {current_value, new_value :: value()} | :pop) ) :: {current_value, new_keywords :: t()} when current_value: value()
Gets the value from key
and updates it. Raises if there is no key
.
This fun
argument receives the value of key
and must return a
two-element tuple: the current value (the retrieved value, which can be
operated on before being returned) and the new value to be stored under
key
.
The returned value is a tuple with the current value returned by fun
and a new
keyword list with the updated value under key
.
Examples
iex> Keyword.get_and_update!([a: 1], :a, fn current_value ->
...> {current_value, "new value!"}
...> end)
{1, [a: "new value!"]}
iex> Keyword.get_and_update!([a: 1], :b, fn current_value ->
...> {current_value, "new value!"}
...> end)
** (KeyError) key :b not found in: [a: 1]
iex> Keyword.get_and_update!([a: 1], :a, fn _ ->
...> :pop
...> end)
{1, []}