Use the
Keyword.put
function to replace duplicate key entries in a keyword list.
If there are no duplicate entries, the entry will just be added.
Keyword.put([a: 1], :b, 2)
[b: 2, a: 1]
If there is a duplicate entry, it will be replaced by the new value.
> Keyword.put([b: 1, a: 1], :b, 2)
[b: 2, a: 1]
If there are multiple duplicate entries, they will all be replaced.
> Keyword.put([b: 3, b: 4, a: 1], :b, 2)
[b: 2, a: 1]