Elixir is a function programming language that I have been using a lot in recent months to build all kinds of applications. Understanding of built-in collection types is essential to use any language effectively and Elixir is no different.
This posts summarizes all collection type along with pros/cons/gotchas for each one of them.
Collection Example When Tuples {:ok, "All good"} Returning data from a function Lists [1, "two", :three] For a collection of items Keyword lists [one: 1, two: 2] Passing options to a function Maps %{one: 1, two: 2} Flexible key/value store Structs %User{name: "John", age: 32} Typed/fixed key/value store Tuples {:ok, foo} “tagged” tuple since begins with an atom like :ok or :error like {:error, 543, "some error"} Examples:
[Read More]