Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR ELIXIR

elixir map to new map

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"}
# ]
Source by hexdocs.pm #
 
PREVIOUS NEXT
Tagged: #elixir #map #map
ADD COMMENT
Topic
Name
5+4 =