Satisfied Interfaces: Category, Cloneable<List<Element>>, Collection<Element>, Correspondence<Integer,Element>, Iterable<Element,Nothing>, List<Element>, Ranged<Integer,List<Element>>, Sequential<Element>
Direct Known Satisfying Classes: ArraySequence<Element>, Range<Element>, Singleton<Element>, Tuple<Element,First,Rest>

A nonempty, immutable sequence of values. The type Sequence<Element>, may be abbreviated [Element+].

Given a possibly-empty sequence of type [Element*], the if (nonempty ...) construct, or, alternatively, the assert (nonempty ...) construct, may be used to narrow to a nonempty sequence type:

[Integer*] nums = ... ;
if (nonempty nums) {
    Integer first = nums.first;
    Integer max = max(nums);
    [Integer+] squares = nums.collect((Integer i) => i**2));
    [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
cloneSource Code
shared actual default [Element+] clone

This nonempty sequence.

Refined declaration: clone
emptySource Code
shared actual Boolean empty

Returns false, since every Sequence contains at least one element.

Refined declaration: empty
firstSource Code
shared formal Element first

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

Refined declaration: first
lastSource Code
shared formal Element last

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

Refined declaration: last
lastIndexSource Code
shared formal Integer lastIndex

The index of the last element of the sequence.

See also: Sequence.size
Refined declaration: lastIndex
restSource Code

The rest of the sequence, without the first element.

Refined declaration: rest
reversedSource Code

Reverse this sequence, returning a new nonempty sequence.

Refined declaration: reversed
sequenceSource Code
shared actual default [Element+] sequence

This nonempty sequence.

Refined declaration: sequence
stringSource Code
shared actual default String string

A developer-friendly string representing the instance. Concatenates the name of the concrete class of the instance with the hash of the instance. Subclasses are encouraged to refine this implementation to produce a more meaningful representation.

Refined declaration: string
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[]
Methods
collectSource Code
shared actual default [Result+] 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.

Refined declaration: collect
findLastSource Code
shared actual default Element? findLast(Boolean selecting(Element elem))

The last element which satisfies the given predicate, if any, or null otherwise.

Refined declaration: findLast
longerThanSource Code
shared actual default Boolean longerThan(Integer length)

Determines if this iterable object has more elements than the given length. This is an efficient operation for iterable objects with many elements.

Refined declaration: longerThan
repeatSource Code
shared actual default Element[] repeat(Integer times)

Returns a list formed by repeating the elements of this iterable object the given number of times, or an empty list if times<=0. An eager counterpart to cycle().

Refined declaration: repeat
shorterThanSource Code
shared actual default Boolean shorterThan(Integer length)

Determines if this iterable object has fewer elements than the given length. This is an efficient operation for iterable objects with many elements.

Refined declaration: shorterThan
sortSource Code
shared actual default [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.

Refined declaration: sort
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>