June 2022
Intermediate to advanced
130 pages
2h 45m
English
In Elixir, you use tuples to create lists of things with a fixed size. You represent a tuple with curly braces surrounding elements with commas between:
| | iex(1)> place = {:stockholm, :sweden} |
| | {:stockholm, :sweden} |
| | iex(2)> origin = {0, 0} |
| | {0, 0} |
| | iex(3)> white = {0xff, 0xff, 0xff} |
| | {255, 255, 255} |
| | iex(4)> success = {:ok, "result"} |
| | {:ok, "result"} |
| | iex(5)> failure = {:error, 401} |
| | {:error, 401} |
Each of these examples is a tuple. A point is an iconic example of a tuple. Erlang developers frequently use tuples to pair return codes with results. Notice that the elements of a tuple aren’t necessarily the same type. For example, in a result tuple from a function, the first element ...
Read now
Unlock full access