Elixir Map
iex> %{"hello" => "world", a: 1, b: 2}
%{:a => 1, :b => 2, "hello" => "world"}
patrick204nqh
iex> %{"hello" => "world", a: 1, b: 2}
%{:a => 1, :b => 2, "hello" => "world"}
users_list = [
%{id: 1, name: "Alice", role: "user", age: 20},
%{id: 2, name: "Bob", role: "admin", age: 30},
%{id: 3, name: "John", role: "editor", age: 40}
]
users = Enum.map(users_list, fn user_struct ->
Map.take(user_struct, [:id, :name])
end)
# [
# %{id: 1, name: "Alice"},
# %{id: 2, name: "Bob"},
# %{id: 3, name: "John"}
# ]