Keyword.merge
You're seeing just the function
merge
, go back to Keyword module for more information.
Specs
Merges two keyword lists into one.
All keys, including duplicated keys, given in keywords2
will be added
to keywords1
, overriding any existing one.
There are no guarantees about the order of keys in the returned keyword.
Examples
iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4])
[b: 2, a: 3, d: 4]
iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4, a: 5])
[b: 2, a: 3, d: 4, a: 5]
iex> Keyword.merge([a: 1], [2, 3])
** (ArgumentError) expected a keyword list as the second argument, got: [2, 3]
Specs
Merges two keyword lists into one.
All keys, including duplicated keys, given in keywords2
will be added
to keywords1
. The given function will be invoked to solve conflicts.
If keywords2
has duplicate keys, the given function will be invoked
for each matching pair in keywords1
.
There are no guarantees about the order of keys in the returned keyword.
Examples
iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4], fn _k, v1, v2 ->
...> v1 + v2
...> end)
[b: 2, a: 4, d: 4]
iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4, a: 5], fn :a, v1, v2 ->
...> v1 + v2
...> end)
[b: 2, a: 4, d: 4, a: 5]
iex> Keyword.merge([a: 1, b: 2, a: 3], [a: 3, d: 4, a: 5], fn :a, v1, v2 ->
...> v1 + v2
...> end)
[b: 2, a: 4, d: 4, a: 8]
iex> Keyword.merge([a: 1, b: 2], [:a, :b], fn :a, v1, v2 ->
...> v1 + v2
...> end)
** (ArgumentError) expected a keyword list as the second argument, got: [:a, :b]