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,
assert (nonempty ...)
, may be used to narrow to a
sequence type 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.
Sequence
has the following subtypes:
ArraySequence
, a sequence backed by an Array
,Range
, an efficient representation of a sequence of
adjacent enumerable values,Tuple
, a typed linked list, andSingleton
, a sequence of just one element.Empty
, ArraySequence
, Range
, Tuple
, Singleton
no type hierarchy
Attributes | |
empty | Source Codeshared actual Boolean empty Returns |
first | Source Codeshared formal Element first The first element of the sequence, that is, the element
with index |
keys | Source Codeshared actual default Range<Integer> keys An integer |
last | Source Codeshared formal Element last The last element of the sequence, that is, the element
with index |
lastIndex | Source Codeshared actual default Integer lastIndex |
rest | Source Codeshared formal Element[] rest The rest of the sequence, without the first element. |
reversed | Source Codeshared actual default [Element+] reversed A sequence containing the elements of this sequence in reverse order to the order in which they occur in this sequence. |
size | Source Codeshared formal Integer size The non-negative length of this sequence, that is, the number of elements in this sequence. |
string | Source Codeshared actual default String string A developer-friendly string representing the instance.
Concatenates the name of the concrete class of the
instance with the |
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[] |
Methods | |
append | Source Codeshared actual default [Element|Other+] append<Other>(Other[] elements) Return a nonempty sequence containing the elements of
this sequence, followed by the given Refines Sequential.append |
clone | Source Codeshared actual default [Element+] clone() This nonempty sequence. |
collect | Source Codeshared 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. |
contains | Source Codeshared actual default Boolean contains(Object element) Returns For most
However, it is possible to form a useful |
find | Source Codeshared actual default Element? find(Boolean selecting(Element&Object elem)) The first element of this stream which satisfies the
given predicate function, if any, or
For example, the expression (-10..10).find(Integer.positive) evaluates to |
findLast | Source Codeshared actual default Element? findLast(Boolean selecting(Element&Object elem)) The last element of this stream which satisfies the
given predicate function, if any, or
For example, the expression (-10..10).findLast(3.divides) evaluates to |
indexes | Source Codeshared actual default Range<Integer> indexes() An integer Refines Iterable.indexes |
longerThan | Source Codeshared actual default Boolean longerThan(Integer length) Determines if this stream has more elements than the
given |
measure | Source Codeshared actual default Element[] measure(Integer from, Integer length) Obtain a measure containing the mapped values starting
from the given starting index, with the given
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 When the given index does not belong to this ranged object, the behavior is implementation dependent. |
prepend | Source Codeshared actual default [Element|Other+] prepend<Other>(Other[] elements) Return a nonempty sequence containing the given
Refines Sequential.prepend |
repeat | Source Codeshared actual default Element[] repeat(Integer times) Produces a sequence formed by repeating the elements of
this sequence the given number of times, or
the empty sequence if |
sequence | Source Codeshared actual default [Element+] sequence() This nonempty sequence. |
shorterThan | Source Codeshared actual default Boolean shorterThan(Integer length) Determines if this stream has fewer elements than the
given |
slice | Source Codeshared actual default Element[][2] slice(Integer index) Return two lists, the first containing the elements
that occur before the given For any list.slice(index) == [list[...index-1], list[index...]] This is an eager operation. |
sort | Source Codeshared 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. Refines Iterable.sort |
span | Source Codeshared actual default Element[] span(Integer from, Integer to) Obtain a span containing the elements between the two given indices. 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 When one or both of the given indices does not belong to this ranged stream, the behavior is implementation dependent. |
spanFrom | Source Codeshared actual default Element[] spanFrom(Integer from) Obtain a span containing the elements between the given starting index and the last index of this ranged object. 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 When the given index does not belong to this ranged stream, the behavior is implementation dependent. |
spanTo | Source Codeshared actual default Element[] spanTo(Integer to) Obtain a span containing the elements between the first index of this ranged stream and given end index. 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 When the given index does not belong to this ranged stream, the behavior is implementation dependent. |
withLeading | Source Codeshared actual default [Other, Element+] withLeading<Other>(Other element) Return a nonempty sequence containing the given
Refines Sequential.withLeading |
withTrailing | Source Codeshared actual default [Element|Other+] withTrailing<Other>(Other element) Return a nonempty sequence containing the elements of
this sequence, followed by the given Refines Sequential.withTrailing |