Satisfied Interfaces: Category, Cloneable<Clone>, Collection<Element>, Container, ContainerWithFirstElement<Element,Null>, Correspondence<Key,Item>, FixedSized<Element>, Iterable<Element>, List<Element>, Ranged<Index,Span>, Sized, Some<Element>
All Known Satisfying Classes: Range, Singleton

A nonempty, immutable sequence of values. A sequence of values may be formed using braces:

value worlds = { "hello", "world" };
value cubes = { for (n in 0..100) n**3 };

The union type Empty|Sequence<Element>, abbreviated Element[], represents a possibly-empty sequence. The if (nonempty ...) construct may be used to obtain an instance of Sequence from a possibly-empty sequence:

Integer[] nums = ... ;
if (nonmpty nums) {
    Integer first = nums.first;
    Integer max = max(nums);
    Sequence<Integer> squares = nums.collect((Integer i) i**2));
    Sequence<Integer> sorted = nums.sort(byIncreasing((Integer i) i));
}

Operations like first, max(), collect(), and sort(), which polymorphically produce a nonempty or non-null output when given a nonempty input are called emptiness-preserving.

By: Gavin
See also: Empty
Attributes
firstSource Code
shared formal Element first

The first element of the sequence, that is, the element with index 0.

lastSource Code
shared actual default Element last

The last element of the sequence, that is, the element with index sequence.lastIndex.

lastIndexSource Code
shared formal Integer lastIndex

The index of the last element of the sequence.

See also: size
restSource Code
shared formal Element[] rest

The rest of the sequence, without the first element.

reversedSource Code
shared formal Sequence<Element> reversed

Reverse this sequence, returning a new nonempty sequence.

sequenceSource Code
shared actual Sequence<Element> sequence

This sequence.

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Cloneable<Clone>
Attributes inherited from: Object
Attributes inherited from: Container
Attributes inherited from: ContainerWithFirstElement<Element,Null>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element>
Attributes inherited from: List<Element>
Attributes inherited from: Sized
Methods
collectSource Code
shared actual Sequence<Element> collect<Result>(Result collecting(Element element))

A nonempty sequence containing the results of applying the given mapping to the elements of this sequence.

Parameters:
  • collecting

    The transformation applied to the elements.

sortSource Code
shared actual default Sequence<Element> sort(Comparison? comparing(Element x, Element y))

A nonempty sequence containing the elements of this container, sorted according to a function imposing a partial order upon the elements.

Parameters:
  • comparing

    The function comparing pairs of elements.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element>
Methods inherited from: Object
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Span>