Want to learn?

Tuples

Representation

Documentation

A tuple is similar to a list since it also stores elements of any type. It is, however, intended as a fixed-size container and therefore you should not manipulate its elements, cause if you do, you should use a list instead. You declare tuple elements inside of curly braces:

iex> {}
{}
iex> {1, :two, "three"}
{1, :two, "three"}

Accessing an element takes constant time, but modifying a tuple, which produces a shallow copy, takes linear time. Tuples are useful for reading data while lists are better for traversals. You will see tuples whenever you want to return multiple values from a function. We have not yet covered this topic, but keep it in mind.

Start a project with your dedicated software house

Top

Contact us

* Required fields

Elo Mordo!Elo Mordo!