Skip to content
Buy me a coffee

Spliterator

Defined in: src/stream/Spliterator.ts:11

Traverses and partitions the elements of a source: the low-level protocol behind streams. It hands out elements one at a time (tryAdvance) or all at once (forEachRemaining), may split off part of its elements (trySplit), and describes the source with a size estimate and characteristic flags (the constants on the Spliterator value). A spliterator is single use and not meant to be shared. Sizes are numbers; an unknown size is reported as Infinity (the reference uses Long.MAX_VALUE). Build a stream over one with StreamSupport.

T

characteristics(): number

Defined in: src/stream/Spliterator.ts:35

Returns the bitwise OR of the characteristic flags (Spliterator.ORDERED, Spliterator.SIZED, …).

number


estimateSize(): number

Defined in: src/stream/Spliterator.ts:31

Returns the estimated number of remaining elements: exact when SIZED, Infinity if unknown or too expensive to compute.

number


forEachRemaining(action): void

Defined in: src/stream/Spliterator.ts:23

Calls action for every remaining element, in encounter order when ORDERED. Usually faster than a tryAdvance loop; afterwards no elements remain.

(t) => void

void

NullPointerException if action is null


getComparator(): ((a, b) => number) | null

Defined in: src/stream/Spliterator.ts:42

Returns the source’s comparator if SORTED (null means natural ordering).

(a, b) => number

Compares a with b: negative if a sorts first, positive if b does, zero if they are equal.

T

T

number


null

IllegalStateException if not SORTED


getExactSizeIfKnown(): number

Defined in: src/stream/Spliterator.ts:33

Returns estimateSize() if SIZED, else -1.

number


hasCharacteristics(characteristics): boolean

Defined in: src/stream/Spliterator.ts:37

Returns true if all the flags in characteristics are set.

number

boolean


tryAdvance(action): boolean

Defined in: src/stream/Spliterator.ts:17

Calls action with the next element if one remains.

(t) => void

boolean

true if an element was passed to action, false when no elements remain

NullPointerException if action is null


trySplit(): Spliterator<T> | null

Defined in: src/stream/Spliterator.ts:29

Splits off a prefix of the remaining elements into a new spliterator and keeps the rest, or returns null if it cannot (or will not) split. Together the pieces cover the elements exactly once, in order. Streams run sequentially and never call it.

Spliterator<T> | null