Class std::Tuple

Implements Iterable

Instances of the Tuple class are fixed-length, immutable sequences of values.

Tuple instances are constructed using the comma operator. By convention, tuple expressions are often placed within parentheses:

(1, 2, "x")    -- 3-tuple with items 1, 2 and "x"
1, 2, "x"      -- Equivalent to above, but without parentheses

There is special syntax for constructing an empty tuple and a single-item tuple:

()             -- An empty tuple
(True,)        -- A single-item tuple

See also: Tuple types in Introduction to Alore Type System.

Tuple methods

length() as Int
Return the length of the tuple.
iterator() as Iterator<Object>
Return an iterator object that can be used to sequentially iterate over the tuple items, starting from the first item.

Tuple operations

Tuple objects support the following operations:

Access tuple items with the indexing operator. The index n must an integer, and it can be negative. Raise the IndexError exception if the index is not within bounds.
var a = ("a", 1, True)
a[0]        -- "a"
a[-1]       -- True
tuple == x, tuple < x
Tuples can be compared for equality and for lexicographic order. All the basic comparison operators are supported: ==, !=, <, <=, > and >=. Tuples can be compared with arrays, and an array and a tuple with the same items are equivalent.
x, y, z = tuple
Tuple objects can be expanded in a multi-assignment or a variable definition. The number of items in the lvalue must equal the length of the tuple.
var a = (1, 3, "x")
var x, y, z = a    -- x gets 1, y gets 3, z gets "x"
for x in tuple
Tuple items can be enumerated with a for loop, starting from the first item.
x in tuple
Test whether a tuple contains a specific object. Return a boolean value. The test is not recursive, i.e., tuples within tuples are not searched.
Return a string representation of the tuple contents.
Return the hash value of a tuple.