23.3 C
New York
Tuesday, April 9, 2024

development – My collector does not collect!


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?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles