Search results

There are no results.

std.tuple

A finite group of values, possibly of different types.

Tuples are finite/fixed-size types that can store up to 8 values, and each value can be of a different type. For example, here's a tuple of 3 values:

(10, "foo", 5.4)

The type of this tuple is (Int, String, Float).

Tuple values are accessed using methods named after the value's position:

let triple = (10, "foo", 5.4)

triple.0 # => 10
triple.1 # => "foo"
triple.2 # => 5.4

When accessing values using thes methods, the value is returned as a reference. If you want to destructure a tuple, you can do so using pattern matching:

match (10, "foo", 5.4) {
  case (a, b, c) -> {
    a # => 10
    b # => "foo"
    c # => 5.4
  }
}

Limitations

Tuples are limited up to 8 values. If you need to store more than 8 values, it's recommended to use a custom class instead. If you really want to use tuples you can always nest them:

(1, 2, 3, 4, 5, 6, 7, (8, 9, 10))

Classes

Tuple1

A 1-ary tuple.

Tuple2

A 2-ary tuple.

Tuple3

A 3-ary tuple.

Tuple4

A 4-ary tuple.

Tuple5

A 5-ary tuple.

Tuple6

A 6-ary tuple.

Tuple7

A 7-ary tuple.

Tuple8

A 8-ary tuple.