Hello all,
I have a list of structs, and I want to iterate through each element and from each element create a new map with multiple keys.
Like the example bellow:
User.list_users() // Returns a list of User structs
|> Map.new(fn user ->
{"#{user.first_name} #{user.last_name}",
%{
"id" => user.id,
"role" => user.role
}}
end)
But what I actually want to return for Phoenix View, is a list with maps like this:
[%{"id" => user.id, "role" => user.role, "name" => user.name}, {"id" => user.id, "role" => user.role, "name" => user.name}, ...]
So this way Phoenix view returns a list of objects like that.
I’m trying to find a solution for this but Map.new() only allows for one key, value pair.
Does anyone know how I could solve this?
Thanks in advance for all the help!