Skip to content

Commit 098b2d7

Browse files
author
José Valim
committed
Ensure Access.at/1 properly pop list elements, closes #4911
Signed-off-by: José Valim <[email protected]>
1 parent d92b7a3 commit 098b2d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/elixir/lib/access.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ defmodule Access do
435435
...> prev -> {prev, String.upcase(prev)}
436436
...> end)
437437
{"john", [%{name: "JOHN"}, %{name: "mary"}]}
438+
439+
`at/1` can also be used to pop elements out of a list or
440+
a key inside of a list:
441+
442+
iex> list = [%{name: "john"}, %{name: "mary"}]
443+
iex> pop_in(list, [Access.at(0)])
444+
{%{name: "john"}, [%{name: "mary"}]}
438445
iex> pop_in(list, [Access.at(0), :name])
439446
{"john", [%{}, %{name: "mary"}]}
440447
@@ -477,7 +484,7 @@ defmodule Access do
477484
defp get_and_update_at([head | rest], 0, next, updates) do
478485
case next.(head) do
479486
{get, update} -> {get, :lists.reverse([update | updates], rest)}
480-
:pop -> {head, :lists.reverse([head | updates], rest)}
487+
:pop -> {head, :lists.reverse(updates, rest)}
481488
end
482489
end
483490

0 commit comments

Comments
 (0)