You’re using Enum.map/2
. That takes a list as an input and returns a list with the same number of elements as output.
Each element of the output is created by the mapper function (the 2nd argument of the Enum.map
).
It’s up to me what I will do with that element.
I can ignore the input completely:
Enum.map([:a, :b, :c], fn _ignoring_element -> :x end)
# [:x, :x, :x]`
I can convert each element to a different “type”:
Enum.map([:a, :b, :c], fn element -> Atom.to_string(element) end)
# ["a", "b", "c"]
And in your case, you can do something similar:
Enum.map(users_list, fn user_struct ->
%{
"a" => user_struct.id,
"b" => user_struct.name,
"c" => DateTime.utc_now(),
"d" => (1 + 2 * 3)
}
end)