Branch
Hash :
6244fe3b
Author :
Thomas de Grivel
Date :
2025-10-21T18:32:49
Make doc
KC3 tuples are immutable arrays of Tag. They contain a fixed number of
constant values of any type. Tuple access is very fast.
Tuples can be used to return more than one value from a function.
For example a successful function call might result in a
{:ok, result} tuple, while an error might produce the
{:error, "Message", data, trace} tuple.
ikc3> a = {:ok, "My title", "Hello, world !"}
{:ok, "My title", "Hello, world !"}
Destructuring works with tuples to extract values :
ikc3> {:ok, title, message} = ^ a
{:ok, "My title", "Hello, world !"}
ikc3> title
"My title"
ikc3> message
"Hello, world !"
The bracket syntax allows you to query the tag at a tuple position :
ikc3> a[0]
:ok
ikc3> a[1]
"My title"
ikc3> a[2]
"Hello, world !"
You can also use the KC3.access function for the same result :
ikc3> a = {:ok, "My title", "Hello, world !"}
{:ok, "My title", "Hello, world !"}
ikc3> access(a, [0])
:ok
ikc3> access(a, [1])
"My title"
ikc3> access(a, [2])
"Hello, world !"
Top : KC3 documentation
Previous : 1.22 Sym
Next : 1.24 Variable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
# 1.23 Tuple
KC3 tuples are immutable arrays of `Tag`. They contain a fixed number of
constant values of any type. Tuple access is very fast.
Tuples can be used to return more than one value from a function.
For example a successful function call might result in a
`{:ok, result}` tuple, while an error might produce the
`{:error, "Message", data, trace}` tuple.
## 1.23.1 Examples
```elixir
ikc3> a = {:ok, "My title", "Hello, world !"}
{:ok, "My title", "Hello, world !"}
```
Destructuring works with tuples to extract values :
```elixir
ikc3> {:ok, title, message} = ^ a
{:ok, "My title", "Hello, world !"}
ikc3> title
"My title"
ikc3> message
"Hello, world !"
```
The bracket syntax allows you to query the tag at a tuple position :
```elixir
ikc3> a[0]
:ok
ikc3> a[1]
"My title"
ikc3> a[2]
"Hello, world !"
```
You can also use the `KC3.access` function for the same result :
```elixir
ikc3> a = {:ok, "My title", "Hello, world !"}
{:ok, "My title", "Hello, world !"}
ikc3> access(a, [0])
:ok
ikc3> access(a, [1])
"My title"
ikc3> access(a, [2])
"Hello, world !"
```
---
Top : [KC3 documentation](../)
Previous : [1.22 Sym](1.22_Sym)
Next : [1.24 Variable](1.24_Variable)