LongStream
Defined in: src/stream/Streams.ts:39
A stream of long integers (JS numbers, exact up to Number.MAX_SAFE_INTEGER). The LongStream value holds the factories.
Extends
Section titled “Extends”LongStream
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”LongStreamType.[dispose]
[iterator]()
Section titled “[iterator]()”[iterator]():
Iterator<number,any,any>
Defined in: site/node_modules/typescript/lib/lib.es2015.iterable.d.ts:47
Returns
Section titled “Returns”Iterator<number, any, any>
Inherited from
Section titled “Inherited from”LongStreamType.[iterator]
allMatch()
Section titled “allMatch()”allMatch(
predicate):boolean
Defined in: src/stream/Stream.ts:382
Returns whether all numbers match predicate; true when empty. Terminal, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(n) => boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”LongStreamType.allMatch
anyMatch()
Section titled “anyMatch()”anyMatch(
predicate):boolean
Defined in: src/stream/Stream.ts:380
Returns whether any number matches predicate; false when empty. Terminal, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(n) => boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”LongStreamType.anyMatch
asDoubleStream()
Section titled “asDoubleStream()”asDoubleStream():
DoubleStream
Defined in: src/stream/Stream.ts:425
Returns the same values as a DoubleStream (no longer reported DISTINCT). Intermediate.
Returns
Section titled “Returns”DoubleStream
Inherited from
Section titled “Inherited from”LongStreamType.asDoubleStream
average()
Section titled “average()”average():
OptionalDouble
Defined in: src/stream/Stream.ts:378
Returns the arithmetic mean, or an empty OptionalDouble for an empty stream. Terminal.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.average
boxed()
Section titled “boxed()”boxed():
Stream<number>
Defined in: src/stream/Stream.ts:390
Returns a Stream of the same numbers, to use object-stream operations such as collect(collector). Intermediate.
Returns
Section titled “Returns”Stream<number>
Inherited from
Section titled “Inherited from”LongStreamType.boxed
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”LongStreamType.close
collect()
Section titled “collect()”collect<
R>(supplier,accumulator,combiner):R
Defined in: src/stream/Stream.ts:368
Performs a mutable reduction into the container supplier creates and returns it. Terminal. Only this
three-argument form exists (call boxed() first to use a Collector); a one-argument call throws
IllegalArgumentException.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”supplier
Section titled “supplier”() => R
accumulator
Section titled “accumulator”(r, n) => void
combiner
Section titled “combiner”(a, b) => void
Returns
Section titled “Returns”R
Inherited from
Section titled “Inherited from”LongStreamType.collect
count()
Section titled “count()”count():
number
Defined in: src/stream/Stream.ts:376
Returns the number of elements; computed without traversal when the size is known exactly. Terminal.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”LongStreamType.count
distinct()
Section titled “distinct()”distinct():
LongStream
Defined in: src/stream/Stream.ts:325
Returns a stream without duplicate numbers, keeping the first occurrence. Intermediate, stateful. NaN equals
NaN; in a DoubleStream -0 and 0 are different values.
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.distinct
dropWhile()
Section titled “dropWhile()”dropWhile(
predicate):LongStream
Defined in: src/stream/Stream.ts:346
Returns the numbers after the longest prefix matching predicate. Intermediate, stateful.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(n) => boolean
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.dropWhile
filter()
Section titled “filter()”filter(
predicate):LongStream
Defined in: src/stream/Stream.ts:309
Returns a stream of the numbers that match predicate. Intermediate, stateless.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(n) => boolean
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.filter
findAny()
Section titled “findAny()”findAny():
OptionalLong
Defined in: src/stream/Stream.ts:388
Returns some number, or an empty optional; always the first here (sequential evaluation). Terminal, short-circuiting.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.findAny
findFirst()
Section titled “findFirst()”findFirst():
OptionalLong
Defined in: src/stream/Stream.ts:386
Returns the first number, or an empty optional. Terminal, short-circuiting.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.findFirst
flatMap()
Section titled “flatMap()”flatMap(
mapper):LongStream
Defined in: src/stream/Stream.ts:318
Returns a stream that replaces each number with the numbers of the stream mapper returns. Intermediate.
A null/undefined result counts as empty; each mapped stream is closed after use.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(n) => LongStream | null | undefined
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.flatMap
forEach()
Section titled “forEach()”forEach(
action):void
Defined in: src/stream/Stream.ts:348
Runs action for each number in encounter order. Terminal.
Parameters
Section titled “Parameters”action
Section titled “action”(n) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”LongStreamType.forEach
forEachOrdered()
Section titled “forEachOrdered()”forEachOrdered(
action):void
Defined in: src/stream/Stream.ts:350
Runs action for each number in encounter order. Terminal; here the same as forEach.
Parameters
Section titled “Parameters”action
Section titled “action”(n) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”LongStreamType.forEachOrdered
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”LongStreamType.isParallel
iterator()
Section titled “iterator()”iterator():
PrimitiveIteratorOfLong
Defined in: src/stream/Stream.ts:419
Returns a PrimitiveIteratorOfLong over the elements; a terminal operation that does not close the stream.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.iterator
limit()
Section titled “limit()”limit(
maxSize):LongStream
Defined in: src/stream/Stream.ts:337
Returns a stream of at most the first maxSize numbers. Intermediate, stateful and short-circuiting.
Parameters
Section titled “Parameters”maxSize
Section titled “maxSize”number
Returns
Section titled “Returns”LongStream
Throws
Section titled “Throws”IllegalArgumentException if maxSize is negative or not an integer
Inherited from
Section titled “Inherited from”LongStreamType.limit
map(
mapper):LongStream
Defined in: src/stream/Stream.ts:311
Returns a stream of mapper applied to each number. Intermediate, stateless.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(n) => number
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.map
mapMulti()
Section titled “mapMulti()”mapMulti(
mapper):LongStream
Defined in: src/stream/Stream.ts:320
Returns a stream of the numbers mapper passes to consumer, zero or more per element. Intermediate, stateless.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(n, consumer) => void
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.mapMulti
mapToDouble()
Section titled “mapToDouble()”mapToDouble(
mapper):DoubleStream
Defined in: src/stream/Stream.ts:423
Returns a DoubleStream of mapper applied to each element. Intermediate.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(n) => number
Returns
Section titled “Returns”DoubleStream
Inherited from
Section titled “Inherited from”LongStreamType.mapToDouble
mapToInt()
Section titled “mapToInt()”mapToInt(
mapper):IntStream
Defined in: src/stream/Stream.ts:421
Returns an IntStream of mapper applied to each element. Intermediate.
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(n) => number
Returns
Section titled “Returns”IntStream
Inherited from
Section titled “Inherited from”LongStreamType.mapToInt
mapToObj()
Section titled “mapToObj()”mapToObj<
U>(mapper):Stream<U>
Defined in: src/stream/Stream.ts:313
Returns a Stream of mapper applied to each number. Intermediate, stateless.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(n) => U
Returns
Section titled “Returns”Stream<U>
Inherited from
Section titled “Inherited from”LongStreamType.mapToObj
max():
OptionalLong
Defined in: src/stream/Stream.ts:374
Returns the largest number (as Math.max: NaN wins), or an empty optional. Terminal.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.max
min():
OptionalLong
Defined in: src/stream/Stream.ts:372
Returns the smallest number (as Math.min: NaN wins), or an empty optional. Terminal.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.min
noneMatch()
Section titled “noneMatch()”noneMatch(
predicate):boolean
Defined in: src/stream/Stream.ts:384
Returns whether no number matches predicate; true when empty. Terminal, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(n) => boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”LongStreamType.noneMatch
onClose()
Section titled “onClose()”onClose(
closeHandler):LongStream
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”LongStream
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”LongStreamType.onClose
parallel()
Section titled “parallel()”parallel():
LongStream
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”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.parallel
peek()
Section titled “peek()”peek(
action):LongStream
Defined in: src/stream/Stream.ts:332
Returns a stream that runs action on each number as it passes. Intermediate, stateless; meant for debugging.
Parameters
Section titled “Parameters”action
Section titled “action”(n) => void
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.peek
reduce()
Section titled “reduce()”Call Signature
Section titled “Call Signature”reduce(
identity,op):number
Defined in: src/stream/Stream.ts:357
Folds the numbers, starting from identity, with an associative op. Terminal.
Parameters
Section titled “Parameters”identity
Section titled “identity”number
(a, b) => number
Returns
Section titled “Returns”number
the result, or identity for an empty stream
Inherited from
Section titled “Inherited from”LongStreamType.reduce
Call Signature
Section titled “Call Signature”reduce(
op):OptionalLong
Defined in: src/stream/Stream.ts:362
Folds the numbers with an associative op, without an initial value. Terminal.
Parameters
Section titled “Parameters”(a, b) => number
Returns
Section titled “Returns”the result, or an empty number optional for an empty stream
Inherited from
Section titled “Inherited from”LongStreamType.reduce
sequential()
Section titled “sequential()”sequential():
LongStream
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”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.sequential
skip()
Section titled “skip()”skip(
n):LongStream
Defined in: src/stream/Stream.ts:342
Returns a stream without the first n numbers (this same stream when n is 0). Intermediate, stateful.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”LongStream
Throws
Section titled “Throws”IllegalArgumentException if n is negative or not an integer
Inherited from
Section titled “Inherited from”LongStreamType.skip
sorted()
Section titled “sorted()”sorted():
LongStream
Defined in: src/stream/Stream.ts:330
Returns a stream sorted in ascending numeric order (-0 before 0). Intermediate and a stateful barrier.
There is no comparator form: use boxed().sorted(cmp); passing one from JS throws IllegalArgumentException.
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.sorted
spliterator()
Section titled “spliterator()”spliterator():
Spliterator<number>
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<number>
Throws
Section titled “Throws”IllegalStateException if the stream was already operated upon or closed
Inherited from
Section titled “Inherited from”LongStreamType.spliterator
sum():
number
Defined in: src/stream/Stream.ts:370
Returns the sum of the numbers, 0 for an empty stream. Terminal.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”LongStreamType.sum
summaryStatistics()
Section titled “summaryStatistics()”summaryStatistics():
LongSummaryStatistics
Defined in: src/stream/Stream.ts:427
Returns the count, sum, min, max and average in one pass. Terminal.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”LongStreamType.summaryStatistics
takeWhile()
Section titled “takeWhile()”takeWhile(
predicate):LongStream
Defined in: src/stream/Stream.ts:344
Returns the longest prefix of numbers matching predicate. Intermediate, short-circuiting.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(n) => boolean
Returns
Section titled “Returns”LongStream
Inherited from
Section titled “Inherited from”LongStreamType.takeWhile
toArray()
Section titled “toArray()”toArray():
number[]
Defined in: src/stream/Stream.ts:352
Returns a new JS array of the numbers in encounter order. Terminal.
Returns
Section titled “Returns”number[]
Inherited from
Section titled “Inherited from”LongStreamType.toArray
unordered()
Section titled “unordered()”unordered():
LongStream
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”LongStream
Throws
Section titled “Throws”IllegalStateException if the stream was already operated upon or closed
Inherited from
Section titled “Inherited from”LongStreamType.unordered