My understanding is that a map implements the Collector protocol and therefore can be used in the into:
part of a comprehension. To try this out, I wrote the following program:
lt = [{"ab", "cd", "ef"}, {"x", "y", "z"}]
m = %{}
for c <- lt, into: m do
IO.puts(length(Map.keys(m)))
{elem(c,1),elem(c,0)}
end
IO.puts(length(Map.keys(m)))
I expected to see
0
1
2
being printed, but I got a 0
each times. It seems that nothing has been collected into the map m
. Why?