Skip to content

Commit d3a5cd2

Browse files
author
Christopher Keele
committed
Add Keyword.delete/3 for deleting explicit values.
1 parent d6de097 commit d3a5cd2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/elixir/lib/keyword.ex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ defmodule Keyword do
211211
lc { _, value } inlist keywords, do: value
212212
end
213213

214+
@doc """
215+
Deletes the entry in the keyword list for a `key` with `value`.
216+
If no `key` with `value` exists, returns the keyword list unchanged.
217+
218+
## Examples
219+
220+
iex> Keyword.delete([a: 1, b: 2], :a, 1)
221+
[b: 2]
222+
223+
iex> Keyword.delete([a: 1, b: 2, a: 3], :a, 3)
224+
[a: 1, b: 2]
225+
226+
iex> Keyword.delete([b: 2], :a, 5)
227+
[b: 2]
228+
229+
"""
230+
@spec delete(t, key, value) :: t
231+
def delete(keywords, key, value) when is_atom(key) do
232+
lc { k, v } = tuple inlist keywords, key != k or value != v, do: tuple
233+
end
234+
214235
@doc """
215236
Deletes all entries in the keyword list for a specific `key`.
216237
If the `key` does not exist, returns the keyword list unchanged.

0 commit comments

Comments
 (0)