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>
All Known Subtypes Hierarchy

- Sequence
  - ArraySequence
  - Range
  - Singleton
  - Tuple

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
clone | Source Code shared actual default [Element+] clone This nonempty sequence. Refined declaration: clone
empty | Source Code shared actual Boolean empty Returns `false`, since every `Sequence` contains at least one element. Refined declaration: empty
first | Source Code shared formal Element first The first element of the sequence, that is, the element with index `0`. Refined declaration: first
last | Source Code shared formal Element last The last element of the sequence, that is, the element with index `sequence.lastIndex`. Refined declaration: last
lastIndex | Source Code shared formal Integer lastIndex The index of the last element of the sequence. See also: Sequence.size Refined declaration: lastIndex
rest | Source Code shared formal Element[] rest The rest of the sequence, without the first element. Refined declaration: rest
reversed | Source Code shared formal [Element+] reversed Reverse this sequence, returning a new nonempty sequence. Refined declaration: reversed
sequence | Source Code shared actual default [Element+] sequence This nonempty sequence. Refined declaration: sequence
string | Source 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 hash
Attributes inherited from: Cloneable<Clone> clone
Attributes inherited from: Collection<Element> string
Attributes inherited from: Correspondence<Key,Item> keys
Attributes inherited from: Iterable<Element,Absent> coalesced, cycled, empty, first, indexed, last, rest, sequence, size, string
Attributes inherited from: List<Element> hash, lastIndex, reversed
Attributes inherited from: Element[] string

Methods
collect | Source 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
findLast | Source 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
longerThan | Source 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
repeat | Source 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
shorterThan | Source 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
sort | Source 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 equals
Methods inherited from: Category contains, containsAny, containsEvery
Methods inherited from: Correspondence<Key,Item> defines, definesAny, definesEvery, get, items
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> endsWith, equals, firstInclusion, firstOccurrence, includes, includesAt, inclusions, indexes, initial, lastInclusion, lastOccurrence, occurrences, occurs, occursAt, startsWith, terminal, trim, trimLeading, trimTrailing, withLeading, withTrailing
Methods inherited from: Ranged<Index,Span> segment, span, spanFrom, spanTo