Tuples
Tuples are fixed-length data structures. Like all Elixir data structures, they are immutable. You can access, or pattern match against, any element of the tuple and you can do so efficiently. This section will show you the types of problems you can generally solve with tuples.
Good Tuples
Generally, think of tuples as structures where the position within the tuple means something. Coordinates, {key, value} pairs from maps, and {city, state} pairs are all good examples of what you’ll see in tuples.
A common and acceptable use for tuples is tagging data. This technique pairs a result tag with data. For example, you’ll see this technique in action with many Elixir functions in return codes like {:ok, value} or {:error, reason}
You’ll also ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access