A tuple is a typed linked list. Each instance of
Tuple
represents the value and type of a single link.
The attributes first
and rest
allow us to retrieve
a value form the list without losing its static type
information.
value point = Tuple(0.0, Tuple(0.0, Tuple("origin"))); Float x = point.first; Float y = point.rest.first; String label = point.rest.rest.first;
Usually, we abbreviate code involving tuples.
[Float,Float,String] point = [0.0, 0.0, "origin"]; Float x = point[0]; Float y = point[1]; String label = point[2];
A list of types enclosed in brackets is an abbreviated
tuple type. An instance of Tuple
may be constructed
by surrounding a value list in brackets:
[String,String] words = ["hello", "world"];
The index operator with a literal integer argument is a
shortcut for a chain of evaluations of rest
and
first
. For example, point[1]
means point.rest.first
.
A terminated tuple type is a tuple where the type of
the last link in the chain is Empty
. An unterminated
tuple type is a tuple where the type of the last link
in the chain is Sequence
or Sequential
. Thus, a
terminated tuple type has a length that is known
statically. For an unterminated tuple type only a lower
bound on its length is known statically.
Here, point
is an unterminated tuple:
String[] labels = ... ; [Float,Float,String*] point = [0.0, 0.0, *labels]; Float x = point[0]; Float y = point[1]; String? firstLabel = point[2]; String[] allLabels = point[2...];
Initializer |
Tuple(First first, Rest rest) Parameters:
|
Attributes | |
clone | Obtain a clone of this object. For a mutable object, this should return a copy of the object. For an immutable object, it is acceptable to return the object itself. Refined declaration: clone |
first | Source Code shared actual First first The first element of this tuple. Refined declaration: first |
last | Source Code shared actual Element last The last element returned by the iterator, if any,
of Refined declaration: last |
lastIndex | Source Code shared actual Integer lastIndex The index of the last element of the list, or null if the list is empty. Refined declaration: lastIndex |
rest | Source Code shared actual Rest rest A tuple with the elements of this tuple, except for the first element. Refined declaration: rest |
reversed | Reverse this list, returning a new list. Refined declaration: reversed |
size | shared actual Integer size The number of elements returned by the iterator of this iterable object, if the iterator terminates. In the case of an iterable whose elements are not countable, this operation never terminates. Refined declaration: size |
Inherited Attributes |
Attributes inherited from: Object |
Attributes inherited from: Cloneable<Clone> |
Attributes inherited from: Collection<Element> |
Attributes inherited from: Correspondence<Key,Item> |
Attributes inherited from: Iterable<Element,Absent> |
Attributes inherited from: List<Element> |
Attributes inherited from: [Element+] |
Attributes inherited from: Element[] |
Methods | |
contains | Source Code Determines if the given value belongs to this
For most Refined declaration: contains |
get | Source Code Returns the value defined for the given key, or
Refined declaration: get |
iterator | Source Code An iterator for the elements belonging to this container. Refined declaration: iterator |
segment | Source Code Obtain a segment containing the mapped values starting from the given index, with the given length. Refined declaration: segment |
span | Source Code Obtain a span containing the mapped values between the two given indices. Refined declaration: span |
spanFrom | Obtain a span containing the mapped values between the starting index and the end of the receiver. Refined declaration: spanFrom |
spanTo | Obtain a span containing the mapped values between the start of the receiver and the end index. Refined declaration: spanTo |
withLeading | Source Code shared actual Tuple<Element|Other,Other,Tuple<Element,First,Rest>> withLeading<Other>(Other element) Returns a new tuple that starts with the specified element, followed by the elements of this tuple. Parameters:
Refined declaration: withLeading |
Inherited Methods |
Methods inherited from: Object |
Methods inherited from: Category |
Methods inherited from: Correspondence<Key,Item> |
Methods inherited from: Iterable<Element,Absent> any, by, chain, collect, count, cycle, defaultNullElements, every, filter, find, findLast, fold, following, iterator, longerThan, map, repeat, select, shorterThan, skipping, skippingWhile, sort, taking, takingWhile |
Methods inherited from: List<Element> |
Methods inherited from: Ranged<Index,Span> |