Stream
Defined in: src/stream/Streams.ts:35
A lazy, single-use sequence of elements supporting aggregate operations: intermediate operations build the
pipeline, one terminal operation runs it. The Stream value holds the factories (Stream.of, Stream.from, …).
Extends
Section titled “Extends”Stream<T>
Type Parameters
Section titled “Type Parameters”T
Methods
Section titled “Methods”[dispose]()
Section titled “[dispose]()”[dispose]():
void
Defined in: src/stream/Stream.ts:71
Calls close(), so using s = ... closes the stream at the end of the block. Present where the runtime has Symbol.dispose.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”StreamType.[dispose]
[iterator]()
Section titled “[iterator]()”[iterator]():
Iterator<T,any,any>
Defined in: site/node_modules/typescript/lib/lib.es2015.iterable.d.ts:47
Returns
Section titled “Returns”Iterator<T, any, any>
Inherited from
Section titled “Inherited from”StreamType.[iterator]
allMatch()
Section titled “allMatch()”allMatch(
predicate):boolean
Defined in: src/stream/Stream.ts:290
Returns whether all elements match predicate; true for an empty stream. Terminal, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”StreamType.allMatch
anyMatch()
Section titled “anyMatch()”anyMatch(
predicate):boolean
Defined in: src/stream/Stream.ts:288
Returns whether any element matches predicate; false for an empty stream. Terminal, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”StreamType.anyMatch
close()
Section titled “close()”close():
void
Defined in: src/stream/Stream.ts:69
Closes the stream and runs its close handlers once, in registration order. If handlers throw, the rest still
run and the first error is rethrown with later ones attached via suppressed. A terminal operation does not
close the stream; closing a closed stream does nothing.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”StreamType.close
collect()
Section titled “collect()”Call Signature
Section titled “Call Signature”collect<
R,A>(collector):R
Defined in: src/stream/Stream.ts:260
Performs a mutable reduction with collector (see Collectors) and returns its result. Terminal.
Type Parameters
Section titled “Type Parameters”R
A
Parameters
Section titled “Parameters”collector
Section titled “collector”Collector<T, A, R>
Returns
Section titled “Returns”R
Inherited from
Section titled “Inherited from”StreamType.collect
Call Signature
Section titled “Call Signature”collect<
R>(supplier,accumulator,combiner):R
Defined in: src/stream/Stream.ts:266
Performs a mutable reduction: supplier creates the container, accumulator adds each element to it. Terminal.
combiner merges the second container into the first; evaluation is sequential so it is never called.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”supplier
Section titled “supplier”() => R
accumulator
Section titled “accumulator”(r, t) => void
combiner
Section titled “combiner”(a, b) => void
Returns
Section titled “Returns”R
the container
Inherited from
Section titled “Inherited from”StreamType.collect
count()
Section titled “count()”count():
number
Defined in: src/stream/Stream.ts:286
Returns the number of elements. Terminal. When the pipeline’s size is known exactly (a sized source and no
filtering stage) the result is computed without traversal, so peek and map callbacks do not run.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”StreamType.count
distinct()
Section titled “distinct()”distinct():
Stream<T>
Defined in: src/stream/Stream.ts:188
Returns a stream without duplicates, by equals()/hashCode() like a HashSet (primitives by value, plain
objects by identity); the first occurrence is kept. Intermediate and stateful (it remembers every element seen)
but not a barrier: each element is emitted the first time it is seen.
Returns
Section titled “Returns”Stream<T>
Inherited from
Section titled “Inherited from”StreamType.distinct
dropWhile()
Section titled “dropWhile()”dropWhile(
predicate):Stream<T>
Defined in: src/stream/Stream.ts:219
Returns the elements after the longest prefix matching predicate. Intermediate, stateful.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”Stream<T>
Inherited from
Section titled “Inherited from”StreamType.dropWhile
filter()
Section titled “filter()”filter(
predicate):Stream<T>
Defined in: src/stream/Stream.ts:151
Returns a stream of the elements that match predicate. Intermediate, stateless.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”Stream<T>
Inherited from
Section titled “Inherited from”StreamType.filter
findAny()
Section titled “findAny()”findAny():
Optional<T>
Defined in: src/stream/Stream.ts:303
Returns some element, or an empty Optional. Terminal, short-circuiting. Evaluation is sequential, so
it is always the first element, as findFirst() returns.
Returns
Section titled “Returns”Optional<T>
Throws
Section titled “Throws”NullPointerException if the element selected is null
Inherited from
Section titled “Inherited from”StreamType.findAny
findFirst()
Section titled “findFirst()”findFirst():
Optional<T>
Defined in: src/stream/Stream.ts:297
Returns the first element, or an empty Optional for an empty stream. Terminal, short-circuiting.
Returns
Section titled “Returns”Optional<T>
Throws
Section titled “Throws”NullPointerException if the element selected is null
Inherited from
Section titled “Inherited from”StreamType.findFirst
flatMap()
Section titled “flatMap()”flatMap<
R>(mapper):Stream<R>
Defined in: src/stream/Stream.ts:165
Returns a stream that replaces each element with the elements of the stream mapper returns. Intermediate.
A null/undefined result counts as an empty stream; each mapped stream is closed after its elements have
been pushed downstream, even when a short-circuit stops the pipeline early.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => Stream<R> | null | undefined
Returns
Section titled “Returns”Stream<R>
Inherited from
Section titled “Inherited from”StreamType.flatMap
flatMapToDouble()
Section titled “flatMapToDouble()”flatMapToDouble(
mapper):DoubleStream
Defined in: src/stream/Stream.ts:171
Like flatMap, with a mapper that returns a DoubleStream; null/undefined counts as empty, each mapped stream is closed.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => DoubleStream | null | undefined
Returns
Section titled “Returns”DoubleStream
Inherited from
Section titled “Inherited from”StreamType.flatMapToDouble
flatMapToInt()
Section titled “flatMapToInt()”flatMapToInt(
mapper):IntStream
Defined in: src/stream/Stream.ts:167
Like flatMap, with a mapper that returns an IntStream; null/undefined counts as empty, each mapped stream is closed.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => IntStream | null | undefined
Returns
Section titled “Returns”IntStream
Inherited from
Section titled “Inherited from”StreamType.flatMapToInt
flatMapToLong()
Section titled “flatMapToLong()”flatMapToLong(
mapper):LongStream
Defined in: src/stream/Stream.ts:169
Like flatMap, with a mapper that returns a LongStream; null/undefined counts as empty, each mapped stream is closed.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => LongStream | null | undefined
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”StreamType.flatMapToLong
forEach()
Section titled “forEach()”forEach(
action):void
Defined in: src/stream/Stream.ts:228
Runs action for each element. Terminal; evaluation is sequential, so elements arrive in encounter order.
Parameters
Section titled “Parameters”action
Section titled “action”(t) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”StreamType.forEach
forEachOrdered()
Section titled “forEachOrdered()”forEachOrdered(
action):void
Defined in: src/stream/Stream.ts:230
Runs action for each element in encounter order. Terminal; here the same as forEach.
Parameters
Section titled “Parameters”action
Section titled “action”(t) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”StreamType.forEachOrdered
gather()
Section titled “gather()”gather<
R>(gatherer):Stream<R>
Defined in: src/stream/Stream.ts:224
Returns a stream transformed by gatherer, a custom intermediate operation (see Gatherers). It
short-circuits when the gatherer’s integrator returns false; the gatherer’s finisher runs at the end.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”gatherer
Section titled “gatherer”Gatherer<T, any, R>
Returns
Section titled “Returns”Stream<R>
Inherited from
Section titled “Inherited from”StreamType.gather
isParallel()
Section titled “isParallel()”isParallel():
boolean
Defined in: src/stream/Stream.ts:44
Returns true if parallel() was requested. It only reports the flag; evaluation is always sequential.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”StreamType.isParallel
iterator()
Section titled “iterator()”iterator():
Iterator<T>
Defined in: src/stream/Stream.ts:35
Returns an Iterator over the stream’s elements. This is a terminal operation; elements are pulled
through the stages lazily, as hasNext()/next() ask for them. Unlike for…of, it does not close the stream.
Returns
Section titled “Returns”Iterator<T>
Throws
Section titled “Throws”IllegalStateException if the stream was already operated upon or closed
Inherited from
Section titled “Inherited from”StreamType.iterator
limit()
Section titled “limit()”limit(
maxSize):Stream<T>
Defined in: src/stream/Stream.ts:210
Returns a stream of at most the first maxSize elements. Intermediate, stateful and short-circuiting.
Parameters
Section titled “Parameters”maxSize
Section titled “maxSize”number
Returns
Section titled “Returns”Stream<T>
Throws
Section titled “Throws”IllegalArgumentException if maxSize is negative or not an integer
Inherited from
Section titled “Inherited from”StreamType.limit
map<
R>(mapper):Stream<R>
Defined in: src/stream/Stream.ts:153
Returns a stream of mapper applied to each element. Intermediate, stateless; a null result flows through like any element.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => R
Returns
Section titled “Returns”Stream<R>
Inherited from
Section titled “Inherited from”StreamType.map
mapMulti()
Section titled “mapMulti()”mapMulti<
R>(mapper):Stream<R>
Defined in: src/stream/Stream.ts:176
Returns a stream of the values mapper passes to consumer, zero or more per element. Intermediate, stateless.
A push-style flatMap that creates no inner streams.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t, consumer) => void
Returns
Section titled “Returns”Stream<R>
Inherited from
Section titled “Inherited from”StreamType.mapMulti
mapMultiToDouble()
Section titled “mapMultiToDouble()”mapMultiToDouble(
mapper):DoubleStream
Defined in: src/stream/Stream.ts:182
Like mapMulti, producing a DoubleStream.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t, consumer) => void
Returns
Section titled “Returns”DoubleStream
Inherited from
Section titled “Inherited from”StreamType.mapMultiToDouble
mapMultiToInt()
Section titled “mapMultiToInt()”mapMultiToInt(
mapper):IntStream
Defined in: src/stream/Stream.ts:178
Like mapMulti, producing an IntStream.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t, consumer) => void
Returns
Section titled “Returns”IntStream
Inherited from
Section titled “Inherited from”StreamType.mapMultiToInt
mapMultiToLong()
Section titled “mapMultiToLong()”mapMultiToLong(
mapper):LongStream
Defined in: src/stream/Stream.ts:180
Like mapMulti, producing a LongStream.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t, consumer) => void
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”StreamType.mapMultiToLong
mapToDouble()
Section titled “mapToDouble()”mapToDouble(
mapper):DoubleStream
Defined in: src/stream/Stream.ts:159
Returns a DoubleStream of mapper applied to each element. Intermediate, stateless.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”DoubleStream
Inherited from
Section titled “Inherited from”StreamType.mapToDouble
mapToInt()
Section titled “mapToInt()”mapToInt(
mapper):IntStream
Defined in: src/stream/Stream.ts:155
Returns an IntStream of mapper applied to each element. Intermediate, stateless.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”IntStream
Inherited from
Section titled “Inherited from”StreamType.mapToInt
mapToLong()
Section titled “mapToLong()”mapToLong(
mapper):LongStream
Defined in: src/stream/Stream.ts:157
Returns a LongStream of mapper applied to each element. Intermediate, stateless.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”StreamType.mapToLong
max(
comparator):Optional<T>
Defined in: src/stream/Stream.ts:281
Returns the largest element by comparator (the first of equal ones), or an empty Optional. Terminal.
Parameters
Section titled “Parameters”comparator
Section titled “comparator”Comparator<T>
Returns
Section titled “Returns”Optional<T>
Throws
Section titled “Throws”NullPointerException if the element selected is null
Inherited from
Section titled “Inherited from”StreamType.max
min(
comparator):Optional<T>
Defined in: src/stream/Stream.ts:276
Returns the smallest element by comparator (the first of equal ones), or an empty Optional. Terminal.
Parameters
Section titled “Parameters”comparator
Section titled “comparator”Comparator<T>
Returns
Section titled “Returns”Optional<T>
Throws
Section titled “Throws”NullPointerException if the element selected is null
Inherited from
Section titled “Inherited from”StreamType.min
noneMatch()
Section titled “noneMatch()”noneMatch(
predicate):boolean
Defined in: src/stream/Stream.ts:292
Returns whether no element matches predicate; true for an empty stream. Terminal, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”StreamType.noneMatch
onClose()
Section titled “onClose()”onClose(
closeHandler):Stream
Defined in: src/stream/Stream.ts:63
Registers a handler run by close() and returns this same stream; handlers run in registration order.
Parameters
Section titled “Parameters”closeHandler
Section titled “closeHandler”() => void
Returns
Section titled “Returns”Stream
Throws
Section titled “Throws”IllegalStateException if the stream was already operated upon or closed
Throws
Section titled “Throws”NullPointerException if closeHandler is null
Inherited from
Section titled “Inherited from”StreamType.onClose
parallel()
Section titled “parallel()”parallel():
Stream
Defined in: src/stream/Stream.ts:51
Sets the parallel flag and returns this same stream. Evaluation stays sequential on the single JS thread;
code written for parallel streams (associative reducers, combiners, findAny) gives the same results.
Returns
Section titled “Returns”Stream
Inherited from
Section titled “Inherited from”StreamType.parallel
peek()
Section titled “peek()”peek(
action):Stream<T>
Defined in: src/stream/Stream.ts:205
Returns a stream that runs action on each element as it passes. Intermediate, stateless; meant for debugging.
Elements that are never pulled (after a short-circuit, or when count() skips traversal) are not seen.
Parameters
Section titled “Parameters”action
Section titled “action”(t) => void
Returns
Section titled “Returns”Stream<T>
Inherited from
Section titled “Inherited from”StreamType.peek
reduce()
Section titled “reduce()”Call Signature
Section titled “Call Signature”reduce(
identity,accumulator):T
Defined in: src/stream/Stream.ts:246
Folds the elements, starting from identity, with an associative accumulator. Terminal.
Parameters
Section titled “Parameters”identity
Section titled “identity”T
accumulator
Section titled “accumulator”(a, b) => T
Returns
Section titled “Returns”T
the result, or identity for an empty stream
Inherited from
Section titled “Inherited from”StreamType.reduce
Call Signature
Section titled “Call Signature”reduce(
accumulator):Optional<T>
Defined in: src/stream/Stream.ts:252
Folds the elements with an associative accumulator, without an initial value. Terminal.
Parameters
Section titled “Parameters”accumulator
Section titled “accumulator”(a, b) => T
Returns
Section titled “Returns”Optional<T>
the result, or an empty Optional for an empty stream
Throws
Section titled “Throws”NullPointerException if the result is null
Inherited from
Section titled “Inherited from”StreamType.reduce
Call Signature
Section titled “Call Signature”reduce<
U>(identity,accumulator,combiner):U
Defined in: src/stream/Stream.ts:258
Folds the elements into a value of another type U, starting from identity. Terminal. combiner merges two
partial results; evaluation is sequential so it is never called, but it must be correct.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”identity
Section titled “identity”U
accumulator
Section titled “accumulator”(u, t) => U
combiner
Section titled “combiner”(a, b) => U
Returns
Section titled “Returns”U
the result, or identity for an empty stream
Inherited from
Section titled “Inherited from”StreamType.reduce
sequential()
Section titled “sequential()”sequential():
Stream
Defined in: src/stream/Stream.ts:46
Clears the parallel flag and returns this same stream. Allowed on a stream that was already used.
Returns
Section titled “Returns”Stream
Inherited from
Section titled “Inherited from”StreamType.sequential
skip()
Section titled “skip()”skip(
n):Stream<T>
Defined in: src/stream/Stream.ts:215
Returns a stream without the first n elements (this same stream when n is 0). Intermediate, stateful.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Stream<T>
Throws
Section titled “Throws”IllegalArgumentException if n is negative or not an integer
Inherited from
Section titled “Inherited from”StreamType.skip
sorted()
Section titled “sorted()”Call Signature
Section titled “Call Signature”sorted():
Stream<T>
Defined in: src/stream/Stream.ts:195
Returns a stream sorted in natural order (numbers numerically, strings by code unit, objects through
compareTo); stable for ordered streams. Intermediate and a stateful barrier: it buffers every element before
emitting any, so it never finishes on an infinite stream. A no-op on a source already in natural order.
Returns
Section titled “Returns”Stream<T>
Throws
Section titled “Throws”ClassCastException (from the terminal operation) for elements that cannot be compared
Inherited from
Section titled “Inherited from”StreamType.sorted
Call Signature
Section titled “Call Signature”sorted(
comparator):Stream<T>
Defined in: src/stream/Stream.ts:200
Returns a stream sorted by comparator; stable for ordered streams. Intermediate and a stateful barrier.
Parameters
Section titled “Parameters”comparator
Section titled “comparator”Comparator<T>
Returns
Section titled “Returns”Stream<T>
Throws
Section titled “Throws”NullPointerException if comparator is null or undefined
Inherited from
Section titled “Inherited from”StreamType.sorted
spliterator()
Section titled “spliterator()”spliterator():
Spliterator<T>
Defined in: src/stream/Stream.ts:42
Returns a Spliterator over the stream’s elements; a terminal operation that pulls elements lazily. It reports the pipeline’s characteristics (ORDERED, DISTINCT, SORTED, SIZED / SUBSIZED as the stages keep them); with no stages it is the source spliterator itself.
Returns
Section titled “Returns”Spliterator<T>
Throws
Section titled “Throws”IllegalStateException if the stream was already operated upon or closed
Inherited from
Section titled “Inherited from”StreamType.spliterator
takeWhile()
Section titled “takeWhile()”takeWhile(
predicate):Stream<T>
Defined in: src/stream/Stream.ts:217
Returns the longest prefix of elements matching predicate. Intermediate, stateful and short-circuiting: it stops at the first failure.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”Stream<T>
Inherited from
Section titled “Inherited from”StreamType.takeWhile
toArray()
Section titled “toArray()”Call Signature
Section titled “Call Signature”toArray():
T[]
Defined in: src/stream/Stream.ts:232
Returns a new JS array of the elements in encounter order. Terminal.
Returns
Section titled “Returns”T[]
Inherited from
Section titled “Inherited from”StreamType.toArray
Call Signature
Section titled “Call Signature”toArray<
A>(generator):A
Defined in: src/stream/Stream.ts:241
Returns the elements in an array-like that generator creates (a typed array, for example). Terminal.
When the stream size is known exactly, generator(size) is called before the traversal and must return an
array of exactly that length. Otherwise it is called with the element count afterwards, and slots past the
elements are set to null. Element type checks of the reference are not emulated.
Type Parameters
Section titled “Type Parameters”A extends WritableArrayLike<T>
Parameters
Section titled “Parameters”generator
Section titled “generator”(length) => A
Returns
Section titled “Returns”A
Throws
Section titled “Throws”IllegalStateException if a sized stream’s generator returns an array of another length
Throws
Section titled “Throws”IndexOutOfBoundsException if an unsized stream’s generator returns a shorter array
Inherited from
Section titled “Inherited from”StreamType.toArray
toList()
Section titled “toList()”toList():
List<T>
Defined in: src/stream/Stream.ts:271
Returns an unmodifiable List of the elements in encounter order. Terminal. Unlike List.of and
Collectors.toUnmodifiableList() it allows null elements; mutators throw UnsupportedOperationException.
Returns
Section titled “Returns”List<T>
Inherited from
Section titled “Inherited from”StreamType.toList
unordered()
Section titled “unordered()”unordered():
Stream
Defined in: src/stream/Stream.ts:57
Returns an equivalent stream without the encounter-order constraint (an intermediate operation), or this stream itself when it is already unordered. Evaluation is sequential, so elements still arrive in source order.
Returns
Section titled “Returns”Stream
Throws
Section titled “Throws”IllegalStateException if the stream was already operated upon or closed
Inherited from
Section titled “Inherited from”StreamType.unordered