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 from 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

no subtypes hierarchy

Initializer
Tuple(First first, Rest rest)
Parameters:
  • first

    The first element of this tuple. (The head of the linked list.)

  • rest

    A tuple with the elements of this tuple, except for the first element. (The tail of the linked list.)

Attributes
firstSource Codeshared actual First first

The first element of this tuple. (The head of the linked list.)

Refines Sequence.first ultimately refines Iterable.first
lastSource Codeshared actual Element last

The last element of this tuple.

Refines Sequence.last ultimately refines Iterable.last
lastIndexSource Codeshared actual Integer lastIndex

The index of the last element of the list, or null if the list is empty. Always size>0 then size-1.

Refines Sequence.lastIndex ultimately refines List.lastIndex
restSource Codeshared actual Rest rest

A tuple with the elements of this tuple, except for the first element. (The tail of the linked list.)

Refines Sequence.rest ultimately refines Iterable.rest
sizeSource Codeshared actual Integer size

The number of elements returned by the Iterable.iterator() of this stream, if the iterator terminates. In the case of an infinite stream, this operation never terminates.

Refines Sequence.size ultimately refines Iterable.size
Inherited Attributes
Attributes inherited from: Object
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
appendSource Codeshared actual [First, <Element|Other>*] append<Other>(Other[] elements)

Return a tuple containing the elements of this tuple, followed by the given elements.

Parameters:
  • elements

    The list of elements to be appended.

Refines Sequence.append ultimately refines Sequential.append
cloneSource Codeshared actual Tuple<Element,First,Rest> clone()

This tuple.

Refines Sequence.clone ultimately refines Collection.clone
containsSource Codeshared actual Boolean contains(Object element)

Determine if the given value is an element of this tuple.

Refines Sequence.contains ultimately refines Category.contains
getFromFirstSource Codeshared actual Element? getFromFirst(Integer index)

The indexth element returned by an iterator of this stream, or null if there are fewer than index+1 elements in the stream. For a stream with an unstable iteration order, a different value might be produced each time getFromFirst(index) is called for a given integer index.

Refines List.getFromFirst ultimately refines Iterable.getFromFirst
iteratorSource Codeshared actual Iterator<Element> iterator()

An iterator for the elements belonging to this stream.

If this is a nonempty stream with type {Element+}, the iterator must produce at least one element.

Refines List.iterator ultimately refines Iterable.iterator
measureSource Codeshared actual Element[] measure(Integer from, Integer length)

Obtain a measure containing the mapped values starting from the given starting index, with the given length. If length<=0, the resulting measure is empty.

For any ranged stream r, r.measure(from, length) may be written using the measure operator:

r[from:length]

The measure should contain the given number of elements of this stream, starting from the element at the given starting index, in the same order as they are produced by the Iterable.iterator() of the stream. In the case where the iterator would be exhausted before length elements are produced, the resulting measure contains only those elements which were produced before the iterator was exhausted, and the length of the measure is less then the given length.

When the given index does not belong to this ranged object, the behavior is implementation dependent.

Refines Sequence.measure ultimately refines Ranged.measure
spanSource Codeshared actual Element[] span(Integer from, Integer end)

Obtain a span containing the elements between the two given indices.

For any ranged stream r, r.span(from, to) may be written using the span operator:

r[from..to]

The span should contain elements of this stream, starting from the element at the given starting index, and ending with the element at the given ending index, in the same order as they are produced by the Iterable.iterator() of the stream, except when the ending index occurs earlier than the starting index, in which case they occur in the opposite order.

When one or both of the given indices does not belong to this ranged stream, the behavior is implementation dependent.

Refines Sequence.span ultimately refines Ranged.span
spanFromSource Codeshared actual Element[] spanFrom(Integer from)

Obtain a span containing the elements between the given starting index and the last index of this ranged object.

For any ranged stream r, r.spanFrom(from) may be written using the span operator:

r[from...]

The span should contain elements of this stream, starting from the element at the given starting index, in the same order as they are produced by the Iterable.iterator() of the stream.

When the given index does not belong to this ranged stream, the behavior is implementation dependent.

Refines Sequence.spanFrom ultimately refines Ranged.spanFrom
spanToSource Codeshared actual Element[] spanTo(Integer to)

Obtain a span containing the elements between the first index of this ranged stream and given end index.

For any ranged stream r, r.spanTo(to) may be written using the span operator:

r[...to]

The span should contain elements of this stream, up to the element at the given ending index, in the same order as they are produced by the Iterable.iterator() of the stream.

When the given index does not belong to this ranged stream, the behavior is implementation dependent.

Refines Sequence.spanTo ultimately refines Ranged.spanTo
withLeadingSource Codeshared actual Tuple<Element|Other,Other,Tuple<Element,First,Rest>> withLeading<Other>(Other element)

Return a new tuple that starts with the specified element, followed by the elements of this tuple.

Parameters:
  • element

    The first element of the resulting tuple.

Refines Sequence.withLeading ultimately refines Sequential.withLeading
withTrailingSource Codeshared actual [First, <Element|Other>+] withTrailing<Other>(Other element)

Return a new tuple containing the elements of this tuple, followed by the given element.

Parameters:
  • element

    The last element of the resulting tuple.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Element,Subrange>
Methods inherited from: [Element+]
Methods inherited from: Element[]