File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments