Tuples are used to group a fixed number of elements together. They can hold any value—even other tuples. They are stored contiguously in memory, which provides constant access time to elements inside a tuple. You create a tuple surrounding the elements with curly brackes ({ and }), and separate the elements with commas:
iex> {:ok, 3.14}{:ok, 3.14}
A common usage of tuples in Elixir is to pattern-match on the result of a function to ensure its success (usually with an :ok atom) or deal with an error. We will be looking to pattern matching and functions later in this chapter.
To access an element inside a tuple, we use the elem function (from the Kernel module), providing the tuple and a zero-based index:
iex> result = {:ok, 3.14}{:ok, ...