Skip to content
Pre-Release: Fe is under active development. This documentation covers the upcoming release. Follow progress on GitHub

Tuples

Tuples group multiple values of different types into a single compound value. They have a fixed length determined at compile time.

Declare a tuple type by listing element types in parentheses:

let point: (i32, i32) = (10, 20)
let mixed: (u256, bool, String<5>) = (100, true, "hello")

Create tuples by listing values in parentheses:

let coordinates: (u256, u256) = (100, 200)
let user_data = (address, balance, is_active)

A single-element tuple requires a trailing comma to distinguish it from a parenthesized expression:

let single: (u256,) = (42,) // This is a tuple
let not_tuple: u256 = (42) // This is just 42

The empty tuple () is called the “unit” type. It represents the absence of a value:

let nothing: () = ()

Functions that don’t return a value implicitly return ().

Access tuple elements by index using dot notation:

let point: (i32, i32, i32) = (10, 20, 30)
let x = point.0 // 10
let y = point.1 // 20
let z = point.2 // 30

Indices start at 0 and must be literal integers. You cannot use a variable as an index.

Extract all tuple elements at once with pattern matching:

let point: (u256, u256) = (100, 200)
let (x, y) = point
// x is 100, y is 200

Use _ to ignore elements you don’t need:

let data = (address, amount, timestamp)
let (_, amount, _) = data // Only extract amount

Accept a tuple parameter and destructure it in the function body:

fn process_point(point: (i32, i32)) -> i32 {
let (x, y) = point
x + y
}

Tuples are commonly used to return multiple values from a function:

fn get_bounds() -> (u256, u256) {
(0, 1000)
}
let (min, max) = get_bounds()

Pass tuples as function arguments:

fn calculate_distance(start: (i32, i32), end: (i32, i32)) -> i32 {
let (x1, y1) = start
let (x2, y2) = end
// ... distance calculation
}

Tuples can contain other tuples:

let nested: ((i32, i32), (i32, i32)) = ((0, 0), (100, 100))
let start = nested.0 // (0, 0)
let start_x = nested.0.0 // 0

Match on tuple patterns:

let point: (u256, u256) = (0, 5)
let location = match point {
(0, 0) => "origin"
(0, _) => "on y-axis"
(_, 0) => "on x-axis"
(_, _) => "somewhere else"
}
SyntaxDescription
(T1, T2, T3)Tuple type with three elements
(a, b, c)Tuple expression
(a,)Single-element tuple
()Empty tuple (unit)
tuple.0Access first element
let (a, b) = tupleDestructure tuple
let (_, b) = tupleDestructure, ignoring first