Elixir Language Converting Lists to a Map


Example

Use Enum.chunk/2 to group elements into sub-lists, and Map.new/2 to convert it into a Map:

[1, 2, 3, 4, 5, 6]
|> Enum.chunk(2)
|> Map.new(fn [k, v] -> {k, v} end)

Would give:

%{1 => 2, 3 => 4, 5 => 6}