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.
| Attributes | |
| first | Source Code shared formal Element first The first element of the sequence, that is, the
element with index |
| last | Source Code shared actual default Element last The last element of the sequence, that is, the
element with index |
| lastIndex | Source Code shared formal Integer lastIndex The index of the last element of the sequence. See also: size |
| rest | Source Code shared formal Element[] rest The rest of the sequence, without the first element. |
| reversed | Source Code Reverse this sequence, returning a new nonempty sequence. |
| sequence | Source Code 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 | |
| collect | Source Code A nonempty sequence containing the results of applying the given mapping to the elements of this sequence. Parameters:
|
| sort | Source Code A nonempty sequence containing the elements of this container, sorted according to a function imposing a partial order upon the elements. Parameters:
|
| 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> |