Tuples in Elixir

31 exercises

About Tuples

Tuples are used commonly to group information informally. A common pattern in Elixir is to group function return values with a status.

# => {:ok, "World"}

# => {:error, :enoent}
  • Tuple literals are enclosed with curly braces, {}.
  • Tuples may hold any data type in contiguous memory, which is allocated when the tuple is created.
  • Tuples allow for constant-time read-access.
  • When manipulating a tuple, rather than mutating the existing tuple, a new one is created.
  • The performance characteristics of tuples make them ideal for storing related information together, but not for storing collections of items that need iterating or might grow or shrink. In the latter case, a list is more appropriate.
  • The Kernel and Tuple modules have useful functions for working with tuples.
Edit via GitHub The link opens in a new window or tab

Learn Tuples

Practicing is locked

Unlock 4 more exercises to practice Tuples