How to create a map from a list of two item tuples in Elixir

siddhadev picture siddhadev · Sep 12, 2014 · Viewed 19.2k times · Source

What would be an elegant way for converting a list of two item tuples like [{1,2},{3,4}] into the map %{1=>2, 3=>4}?

Keyword list would be trivial, but what if we have arbitrary keys?

Answer

bitwalker picture bitwalker · Sep 16, 2014

The simplest way to do this is:

Enum.into(list, %{})