-
Notifications
You must be signed in to change notification settings - Fork 1
Tuples
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.
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.
Tuples list each of their elements' types as attributes:
tuple<bool, str, func<int>> myTuple = {
true,
"tuple element",
func<int>() {
return 123;
},
};