Converting a list of maps to a simple list (based on one value from each map)

I have this list:

[%{item: 20706}, %{item: 20704}]

I want to convert it to:

[20706, 20704]

How to do that? Thank you.

Maybe something like this

list = [%{item: 20706}, %{item: 20704}]
list |> Enum.map(& Map.get(&1, :item))
5 Likes

The Access functions can make this really nice:

iex(7)> list = [%{item: 20706}, %{item: 20704}]       
[%{item: 20706}, %{item: 20704}]
iex(8)> get_in list, [Access.all(), :item]     
[20706, 20704]
5 Likes