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.
| Attributes | |
| clone | Source Code This nonempty sequence. Refined declaration: clone |
| empty | Source Code shared actual Boolean empty Returns Refined declaration: empty |
| first | Source Code shared formal Element first The first element of the sequence, that is, the
element with index Refined declaration: first |
| last | Source Code shared formal Element last The last element of the sequence, that is, the
element with index 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 The rest of the sequence, without the first element. Refined declaration: rest |
| reversed | Source Code Reverse this sequence, returning a new nonempty sequence. Refined declaration: reversed |
| sequence | Source Code 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 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 | |
| collect | Source Code A nonempty sequence containing the results of applying the given mapping to the elements of this sequence. Parameters:
Refined declaration: collect |
| findLast | Source Code The last element which satisfies the given
predicate, if any, or Refined declaration: findLast |
| longerThan | Source Code 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 Returns a list formed by repeating the elements of this
iterable object the given number of times, or an empty
list if Refined declaration: repeat |
| shorterThan | Source Code 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 A nonempty sequence containing the elements of this container, sorted according to a function imposing a partial order upon the elements. Parameters:
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> 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> |
| Methods inherited from: Ranged<Index,Span> |