Skip to content
Matt Basta edited this page Feb 17, 2015 · 3 revisions

Tuples are objects that live on the heap. They can have up to 255 elements of mixed types (primitives and otherwise). Tuples are immutable, though their contents may not necessarily be immutable.

A tuple is created using the tuple literal syntax:

var foo = [: 1, "foo", false];

Tuple literals cannot contain null as a direct value, because null is typed in BType. Instead, null can be cast to a type:

var foo = [: 1, null as MyObject];

Tuples may contain one optional trailing comma within the curly braces.

Purpose

Tuples are meant to function as a lightweight means of passing related values and objects around within an application. For example, a function can use a tuple to return multiple values.

Tuples are NOT intended to be used as a data structure for organizing information. That is, you should not use tuples in lieu of arrays, slices, or maps.

Type Signature

Tuples list each of their elements' types as attributes:

tuple<bool, str, func<int>> myTuple = {
    true,
    "tuple element",
    func<int>() {
        return 123;
    },
};