A sequence with no elements. The type Empty may be abbreviated [], and an instance is produced by the expression []. That is, in the following expression, none has type [] and refers to the value []:

[] none = [];

(Whether the syntax [] refers to the type or the value depends upon how it occurs grammatically.)

See also Sequence

no type hierarchy

Attributes
coalescedSource Codeshared actual [] coalesced

Returns [].

cycledSource Codeshared actual [] cycled

Returns [].

emptySource Codeshared actual Boolean empty

Returns true.

Refines Collection.empty ultimately refines Iterable.empty
firstSource Codeshared actual Null first

Returns null.

Refines List.first ultimately refines Iterable.first
indexedSource Codeshared actual [] indexed

Returns [].

keysSource Codeshared actual [] keys

Returns [].

Refines Sequential.keys ultimately refines Correspondence.keys
lastSource Codeshared actual Null last

Returns null.

Refines List.last ultimately refines Iterable.last
lastIndexSource Codeshared actual Null lastIndex

Returns null.

pairedSource Codeshared actual [] paired

Returns [].

restSource Codeshared actual [] rest

Returns [].

Refines Sequential.rest ultimately refines Iterable.rest
reversedSource Codeshared actual [] reversed

Returns [].

Refines Sequential.reversed ultimately refines List.reversed
sizeSource Codeshared actual Integer size

Returns 0.

Refines Sequential.size ultimately refines Iterable.size
stringSource Codeshared actual String string

Returns a string description of the empty sequence: [].

Refines Sequential.string ultimately refines Object.string
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
anySource Codeshared actual Boolean any(Boolean selecting(Nothing element))

Determines if there is at least one element of this stream that satisfies the given predicate function. If the stream is empty, returns false. For an infinite stream, this operation might not terminate.

Refines Iterable.any
appendSource Codeshared actual Other[] append<Other>(Other[] elements)

Return a sequence containing the elements of this sequence, in the order in which they occur in this sequence, followed by the given elements, in the order in which they occur in the given sequence.

bySource Codeshared actual [] by(Integer step)

Produces a stream containing every stepth element of this stream. If the step size is 1, the resulting stream contains the same elements as this stream.

For example, the expression

(0..10).by(3)

results in the stream { 0, 3, 6, 9 }.

The step size must be greater than zero.

Refines Iterable.by
chainSource Codeshared actual Iterable<Other,OtherAbsent> chain<Other, OtherAbsent>(Iterable<Other,OtherAbsent> other)
given OtherAbsent satisfies Null

Returns the given other iterable object.

cloneSource Codeshared actual [] clone()

Returns [].

Refines Sequential.clone ultimately refines Collection.clone
collectSource Codeshared actual [] collect<Result>(Result collecting(Nothing element))

Produce a new sequence containing the results of applying the given mapping to the elements of this stream.

This operation is an eager counterpart to Iterable.map(). For any stream it, and mapping f:

it.collect(f) == [*it.map(f)]
Refines List.collect ultimately refines Iterable.collect
containsSource Codeshared actual Boolean contains(Object element)

Returns false for any given element.

Refines List.contains ultimately refines Category.contains
countSource Codeshared actual Integer count(Boolean selecting(Nothing element))

Returns 0 for any given predicate.

defaultNullElementsSource Codeshared actual [] defaultNullElements<Default>(Default defaultValue)
given Default satisfies Object

Produces a stream containing the elements of this stream, in the order in which they occur in this stream, after replacing every null element in the stream with the given default value. The value null does not ocur in the resulting stream.

For example, the expression

{ "123", "abc", "456" }.map(parseInteger).defaultNullElements(0)

results in the stream { 123, 0, 456 }.

definesSource Codeshared actual Boolean defines(Integer index)

Returns false for any given index.

Refines List.defines ultimately refines Correspondence.defines
eachSource Codeshared actual void each(void step(Nothing element))

Call the given function for each element of this stream, passing the elements in the order they occur in this stream.

For example:

words.each((word) {
    print(word.lowercased);
    print(word.uppercased);
});

Has the same effect as the following for loop:

for (word in words) {
    print(word.lowercased);
    print(word.uppercased);
}

For certain streams this method is highly efficient, surpassing the performance of for loops on the JVM. Thus, each() is sometimes preferred in highly performance-critical low-level code.

everySource Codeshared actual Boolean every(Boolean selecting(Nothing element))

Determines if all elements of this stream satisfy the given predicate function. If the stream is empty, return true. For an infinite stream, this operation might not terminate.

filterSource Codeshared actual [] filter(Boolean selecting(Nothing element))

Produces a stream containing the elements of this stream that satisfy the given predicate function.

For any empty stream, filter() returns an empty stream:

{}.filter(p) == {}

For any nonempty stream it, and predicate p, the result of filter() may be obtained according to this recursive definition:

it.filter(p) == { if (p(it.first)) it.first }.chain(it.rest.filter(f))

Alternatively, and in practice, filter() may be defined by this comprehension:

it.filter(p) == { for (e in it) if (p(e)) e };

For example, the expression

(1..100).filter(13.divides)

results in the stream { 13, 26, 39, 52, 65, 78, 91 }.

findSource Codeshared actual Null find(Boolean selecting(Nothing element))

The first element of this stream which is not null and satisfies the given predicate function, if any, or null if there is no such element. For an infinite stream, this method might not terminate.

For example, the expression

(-10..10).find(Integer.positive)

evaluates to 1.

Refines List.find ultimately refines Iterable.find
firstIndexWhereSource Codeshared actual Null firstIndexWhere(Boolean selecting(Nothing element))

The first index in this list for which the element is not null and satisfies the given predicate function.

flatMapSource Codeshared actual [] flatMap<Result, OtherAbsent>(Iterable<Result,OtherAbsent> collecting(Nothing element))
given OtherAbsent satisfies Null

Given a mapping function that accepts an Element and returns a stream of Results, produces a new stream containing all elements of every Result stream that results from applying the function to the elements of this stream.

For example, the expression

{ "Hello", "World" }.flatMap(String.lowercased)

results in this stream:

{ 'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r,' 'l', 'd' }

The expression

{ "hello"->"hola", "world"->"mundo" }
        .flatMap(Entry<String,String>.pair)

produces this stream:

{ "hello", "hola", "world", "mundo" }
foldSource Codeshared actual Result fold<Result>(Result initial)(Result accumulating(Result partial, Nothing element))

Beginning with a given initial value, apply the given combining function to each element of this stream in turn, progressively accumulating a single result.

For an empty stream, fold() returns the given initial value z:

{}.fold(z)(f) == z

For a given nonempty stream it, initial value z, and combining function f, the result of fold() is obtained according to the following recursive definition:

it.fold(z)(f) == f(it.exceptLast.fold(z)(f), it.last)

For example, the expression

(1..100).fold(0)(plus)

results in the integer 5050.

followSource Codeshared actual {Other+} follow<Other>(Other head)

Produces a stream with a given initial element, followed by the elements of this stream, in the order in which they occur in this stream.

For example, the expression

(1..3).follow(0)

evaluates to the stream { 0, 1, 2, 3 }.

Note that the expression stream.follow(head) eagerly evaluates head, and therefore is not precisely the same as this enumeration expression, where head is evaluated lazily:

{ head, *stream }
getFromFirstSource Codeshared actual Null getFromFirst(Integer index)

Returns null for any given index.

Refines List.getFromFirst ultimately refines Iterable.getFromFirst
getFromLastSource Codeshared actual Null getFromLast(Integer index)

Returns null for any given index.

indexesSource Codeshared actual [] indexes()

Returns [].

indexesWhereSource Codeshared actual [] indexesWhere(Boolean selecting(Nothing element))

The indexes in this list for which the element is not null and satisfies the given predicate function.

initialSource Codeshared actual [] initial(Integer length)

Select the first elements of this list, returning a list no longer than the given length. If this list is shorter than the given length, return this list. Otherwise return a list of the given length. If length<=0 return an empty list.

For any list, and for any integer length:

list.initial(length) == list[...length-1] == list[0:length]

This is an eager operation.

Refines Sequential.initial ultimately refines List.initial
iteratorSource Codeshared actual Iterator<Nothing> iterator()

Returns an iterator that is already exhausted.

Refines List.iterator ultimately refines Iterable.iterator
lastIndexWhereSource Codeshared actual Null lastIndexWhere(Boolean selecting(Nothing element))

The last index in this list for which the element is not null and satisfies the given predicate function.

mapSource Codeshared actual [] map<Result>(Result collecting(Nothing element))

Produces a stream containing the results of applying the given mapping to the elements of this stream.

For any empty stream, map() returns an empty stream:

{}.map(f) == {}

For any nonempty stream it, and mapping function f, the result of map() may be obtained according to this recursive definition:

it.map(f).first == f(it.first)
it.map(f).rest == it.rest.map(f)

Alternatively, and in practice, map() may be defined by this comprehension:

it.map(f) == { for (e in it) f(e) }

For example, the expression

(0..4).map(10.power)

results in the stream { 1, 10, 100, 1000, 10000 }.

Refines Iterable.map
measureSource Codeshared actual [] measure(Integer from, Integer length)

Returns [] for any given measure.

Refines List.measure ultimately refines Ranged.measure
prependSource Codeshared actual Other[] prepend<Other>(Other[] elements)

Return a sequence containing the given elements, in the order in which they occur in the given sequence, followed by the elements of this sequence, in the order in which they occur in this sequence.

reduceSource Codeshared actual Null reduce<Result>(Result accumulating(Result partial, Nothing element))

Beginning with the Iterable.first element of this stream, apply the given combining function to each element of this stream in turn, progressively accumulating a single result.

For an empty stream, reduce() always returns null.

For a stream with one element, reduce() returns that element:

{ first }.reduce(f) == first

For a given stream it with more than one element, and combining function f, the result of reduce() is obtained according to the following recursive definition:

it.reduce(f) == f(it.exceptLast.reduce(f), it.last)

For example, the expression

(1..100).reduce(plus)

results in the integer 5050.

repeatSource Codeshared actual [] repeat(Integer times)

Returns [].

Refines Sequential.repeat ultimately refines Iterable.repeat
selectSource Codeshared actual [] select(Boolean selecting(Nothing element))

Produce a new sequence containing all elements of this stream that satisfy the given predicate function, in the order in which they occur in this stream.

This operation is an eager counterpart to Iterable.filter(). For any stream it, and predicate p:

it.select(p) == [*it.filter(p)]
sequenceSource Codeshared actual [] sequence()

Returns [].

Refines Sequential.sequence ultimately refines Iterable.sequence
skipSource Codeshared actual [] skip(Integer skipping)

Produces a stream containing the elements of this stream, after skipping the first skipping elements produced by its iterator.

If this stream does not contain more elements than the specified number of elements to skip, the resulting stream has no elements. If the specified number of elements to skip is zero or fewer, the resulting stream contains the same elements as this stream.

skipWhileSource Codeshared actual [] skipWhile(Boolean skipping(Nothing elem))

Produces a stream containing the elements of this stream, after skipping the leading elements until the given predicate function returns false.

sliceSource Codeshared actual [][2] slice(Integer index)

Return two lists, the first containing the elements that occur before the given index, the second with the elements that occur after the given index. If the given index is outside the range of indexes of this list, one of the returned lists will be empty.

For any list, and for any integer index:

list.slice(index) == [list[...index-1], list[index...]]

This is an eager operation.

Refines Sequential.slice ultimately refines List.slice
sortSource Codeshared actual [] sort(Comparison comparing(Nothing a, Nothing b))

Produce a new sequence containing the elements of this stream, sorted according to the given comparator function imposing a partial order upon the elements of the stream.

For convenience, the functions byIncreasing() and byDecreasing() produce suitable comparator functions.

For example, this expression

"Hello World!".sort(byIncreasing(Character.lowercased))

evaluates to the sequence [ , !, d, e, H, l, l, l, o, o, r, W].

This operation is eager by nature.

Note that the toplevel function sort() may be used to sort a stream of Comparable values according to the natural order of its elements.

spanSource Codeshared actual [] span(Integer from, Integer to)

Returns [] for any given span.

Refines List.span ultimately refines Ranged.span
spanFromSource Codeshared actual [] spanFrom(Integer from)

Returns [] for any given span.

Refines List.spanFrom ultimately refines Ranged.spanFrom
spanToSource Codeshared actual [] spanTo(Integer to)

Returns [] for any given span.

Refines List.spanTo ultimately refines Ranged.spanTo
spreadSource Codeshared actual [](*Args) spread<Result, Args>(Result(*Args) method(Nothing element))

Given a method() of the element type Element, return a function that, when supplied with a list of method arguments, produces a new iterable object that applies the method to each element of this iterable object in turn.

{Boolean+}(Object) fun = (-1..1).spread(Object.equals);
print(fun(0)); //prints { false, true, false }
sublistSource Codeshared actual [] sublist(Integer from, Integer to)

A sublist of this list, starting at the element with index from, ending at the element with the index to.

This is a lazy operation, returning a view of this list.

Refines List.sublist
sublistFromSource Codeshared actual [] sublistFrom(Integer from)

A sublist of this list, starting at the element with the given index.

This is a lazy operation, returning a view of this list.

sublistToSource Codeshared actual [] sublistTo(Integer to)

A sublist of this list, ending at the element with the given index.

This is a lazy operation, returning a view of this list.

takeSource Codeshared actual [] take(Integer taking)

Produces a stream containing the first taking elements of this stream.

If the specified number of elements to take is larger than the number of elements of this stream, the resulting stream contains the same elements as this stream. If the specified number of elements to take is fewer than one, the resulting stream has no elements.

takeWhileSource Codeshared actual [] takeWhile(Boolean taking(Nothing elem))

Produces a stream containing the leading elements of this stream until the given predicate function returns false.

terminalSource Codeshared actual [] terminal(Integer length)

Select the last elements of the list, returning a list no longer than the given length. If this list is shorter than the given length, return this list. Otherwise return a list of the given length.

For any list, and for any integer length:

list.terminal(length) == list[size-length...]

This is an eager operation.

Refines Sequential.terminal ultimately refines List.terminal
trimSource Codeshared actual [] trim(Boolean trimming(Nothing elem))

Trim the elements satisfying the given predicate function, along with any null elements, from the start and end of this list, returning a list no longer than this list.

This is an eager operation.

Refines Sequential.trim ultimately refines List.trim
trimLeadingSource Codeshared actual [] trimLeading(Boolean trimming(Nothing elem))

Trim the elements satisfying the given predicate function, along with any null elements, from the start of this list, returning a list no longer than this list.

This is an eager operation.

Refines Sequential.trimLeading ultimately refines List.trimLeading
trimTrailingSource Codeshared actual [] trimTrailing(Boolean trimming(Nothing elem))

Trim the elements satisfying the given predicate function, along with any null elements, from the end of this list, returning a list no longer than this list.

This is an eager operation.

Refines Sequential.trimTrailing ultimately refines List.trimTrailing
withLeadingSource Codeshared actual [Other] withLeading<Other>(Other element)

Returns a new sequence that starts with the specified element, followed by the elements of this sequence, in the order they occur in this sequence.

withTrailingSource Codeshared actual [Other] withTrailing<Other>(Other element)

Returns a new sequence that starts with the elements of this sequence, in the order they occur in this sequence, and ends with the specified element.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Element,Subrange>
Methods inherited from: Element[]