Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/elixir/lib/keyword.ex
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ defmodule Keyword do
{get, :lists.reverse(acc, [{key, value} | delete(t, key)])}

:pop ->
{current, :lists.reverse(acc, t)}
{current, :lists.reverse(acc, delete(t, key))}

other ->
raise "the given function must return a two-element tuple or :pop, got: #{inspect(other)}"
Expand Down Expand Up @@ -583,7 +583,7 @@ defmodule Keyword do
{get, :lists.reverse(acc, [{key, value} | delete(t, key)])}

:pop ->
{value, :lists.reverse(acc, t)}
{value, :lists.reverse(acc, delete(t, key))}

other ->
raise "the given function must return a two-element tuple or :pop, got: #{inspect(other)}"
Expand Down
4 changes: 4 additions & 0 deletions lib/elixir/test/elixir/keyword_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ defmodule KeywordTest do
test "get_and_update/3 removes duplicates from the input keyword list" do
assert Keyword.get_and_update([a: 1, b: 2, a: 3], :a, fn value -> {value, value + 10} end) ==
{1, [a: 11, b: 2]}

assert Keyword.get_and_update([a: 1, b: 2, a: 3], :a, fn _ -> :pop end) == {1, [b: 2]}
end

test "get_and_update/3 raises on bad return value from the argument function" do
Expand All @@ -50,6 +52,8 @@ defmodule KeywordTest do
test "get_and_update!/3 removes duplicates from the input keyword list" do
assert Keyword.get_and_update!([a: 1, b: 2, a: 3], :a, fn value -> {value, value + 10} end) ==
{1, [a: 11, b: 2]}

assert Keyword.get_and_update!([a: 1, b: 2, a: 3], :a, fn _ -> :pop end) == {1, [b: 2]}
end

test "get_and_update!/3 raises on bad return value from the argument function" do
Expand Down
Loading