Tuples
A tuple groups a fixed number of values of possibly-different types into one. Unlike a record, a tuple’s elements are positional: you reach them by their position, not by a field name.
Tuples are written with the #(...) syntax. The hash distinguishes
them from parenthesized expressions.
Creating tuples
Section titled “Creating tuples”let point = #(1.0, 2.0) // #(Double, Double)let tagged = #("active", 42) // #(String, Int)let nested = #(#(0, 0), #(1, 1)) // tuple of tuplesThere is no one-element tuple. #(x) is not a valid syntax; a single
value is just the value.
Destructuring
Section titled “Destructuring”Tuples destructure in let, in for..in heads, in match arms, and
in function parameters whose types are tuples.
let #(x, y) = pointdebug "x=${x}, y=${y}"
// Ignore an element with _let #(_, y) = point
// In a for loopfor #(index, value) in entries { debug "${index}: ${value}"}
// In matchfn describe(p: #(Int, Int)): String { match p { #(0, 0) => "origin", #(_, 0) => "on x-axis", #(0, _) => "on y-axis", #(x, y) => "point (${x}, ${y})", }}Where tuples are useful
Section titled “Where tuples are useful”- Returning two values.
(name, age),(line, column),(ok, reason). - Map entries.
Map.of([#("Alice", 30), #("Bob", 25)])uses a list of 2-tuples as key-value pairs. - Enumerated iteration.
list.enumerate()returnsList<#(Int, T)>.
If the elements are meaningfully named, prefer a type with named
fields instead:
// Prefer a named record when the fields have meaningtype Location { Location(line: Int, column: Int)}
// Tuple is fine when the role of each slot is obvious from contextfn minMax(xs: List<Int>): Option<#(Int, Int)> { ... }Tuples are values
Section titled “Tuples are values”Tuples are compared by structural equality (element-wise): two tuples of the same type with equal elements are equal.
let a = #(1, "x")let b = #(1, "x")debug a == b // trueCodegen
Section titled “Codegen”Tuples emit as a Vertex-internal record in the generated Apex. You rarely need to reason about this; they behave as ordinary values at both the Vertex and Apex levels.