Skip to content

Tuple

A Tuple is typically created with a tuple literal:

tuple = {1, "hello", 'x'} # Tuple(Int32, String, Char)
tuple[0]                  # => 1       (Int32)
tuple[1]                  # => "hello" (String)
tuple[2]                  # => 'x'     (Char)

To create an empty tuple use Tuple.new.

To denote a tuple type you can write:

# The type denoting a tuple of Int32, String and Char
Tuple(Int32, String, Char)

In type restrictions, generic type arguments and other places where a type is expected, you can use a shorter syntax, as explained in the type grammar:

# An array of tuples of Int32, String and Char
Array({Int32, String, Char})