Type Hierarchy:
Satisfied Interfaces: Category, Cloneable<List<Element>>, Collection<Element>, Correspondence<Integer,Element>, Iterable<Element,Nothing>, List<Element>, Ranged<Integer,List<Element>>, Sequence<Element>, Sequential<Element>

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...];
By: Gavin
Tuple(First first, Rest rest)
  • first

    The first element of this tuple.

  • rest

    A tuple with the elements of this tuple, except for the first element.

shared actual Tuple<Element,First,Rest> 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
firstSource Code
shared actual First first

The first element of this tuple.

Refined declaration: first
lastSource Code
shared actual Element last

The last element returned by the iterator, if any, of null if the iterable object is empty. Iterable objects are potentially infinite, so calling this might never return; also, this implementation will iterate through all the elements, which might be very time-consuming.

Refined declaration: last
lastIndexSource Code
shared actual Integer lastIndex

The index of the last element of the list, or null if the list is empty.

Refined declaration: lastIndex
restSource Code
shared actual Rest rest

A tuple with the elements of this tuple, except for the first element.

Refined declaration: rest

Reverse this list, returning a new list.

Refined declaration: reversed
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[]
containsSource Code
shared actual Boolean contains(Object element)

Determines if the given value belongs to this Category, that is, if it is an element of this Category.

For most Categorys, if x==y, then category.contains(x) evaluates to the same value as category.contains(y). However, it is possible to form a Category consistent with some other equivalence relation, for example ===. Therefore implementations of contains() which do not satisfy this relationship are tolerated.

Refined declaration: contains
getSource Code

Returns the value defined for the given key, or null if there is no value defined for the given key.

Refined declaration: get
iteratorSource Code
shared actual Iterator<Element> iterator()

An iterator for the elements belonging to this container.

Refined declaration: iterator
segmentSource Code

Obtain a segment containing the mapped values starting from the given index, with the given length.

Refined declaration: segment
spanSource Code

Obtain a span containing the mapped values between the two given indices.

Refined declaration: span

Obtain a span containing the mapped values between the starting index and the end of the receiver.

Refined declaration: spanFrom

Obtain a span containing the mapped values between the start of the receiver and the end index.

Refined declaration: spanTo
withLeadingSource 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.

  • element

    The first element of the resulting tuple.

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>
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Span>