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.
Type Parameters
Section titled “Type Parameters”T
Methods
Section titled “Methods”characteristics()
Section titled “characteristics()”characteristics():
number
Defined in: src/stream/Spliterator.ts:35
Returns the bitwise OR of the characteristic flags (Spliterator.ORDERED, Spliterator.SIZED, …).
Returns
Section titled “Returns”number
estimateSize()
Section titled “estimateSize()”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.
Returns
Section titled “Returns”number
forEachRemaining()
Section titled “forEachRemaining()”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.
Parameters
Section titled “Parameters”action
Section titled “action”(t) => void
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if action is null
getComparator()
Section titled “getComparator()”getComparator(): ((
a,b) =>number) |null
Defined in: src/stream/Spliterator.ts:42
Returns the source’s comparator if SORTED (null means natural ordering).
Returns
Section titled “Returns”Function
Section titled “Function”(a, b) => number
Compares a with b: negative if a sorts first, positive if b does, zero if they are equal.
Parameters
Section titled “Parameters”T
T
Returns
Section titled “Returns”number
null
Throws
Section titled “Throws”IllegalStateException if not SORTED
getExactSizeIfKnown()
Section titled “getExactSizeIfKnown()”getExactSizeIfKnown():
number
Defined in: src/stream/Spliterator.ts:33
Returns estimateSize() if SIZED, else -1.
Returns
Section titled “Returns”number
hasCharacteristics()
Section titled “hasCharacteristics()”hasCharacteristics(
characteristics):boolean
Defined in: src/stream/Spliterator.ts:37
Returns true if all the flags in characteristics are set.
Parameters
Section titled “Parameters”characteristics
Section titled “characteristics”number
Returns
Section titled “Returns”boolean
tryAdvance()
Section titled “tryAdvance()”tryAdvance(
action):boolean
Defined in: src/stream/Spliterator.ts:17
Calls action with the next element if one remains.
Parameters
Section titled “Parameters”action
Section titled “action”(t) => void
Returns
Section titled “Returns”boolean
true if an element was passed to action, false when no elements remain
Throws
Section titled “Throws”NullPointerException if action is null
trySplit()
Section titled “trySplit()”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.
Returns
Section titled “Returns”Spliterator<T> | null