Skip to content
Buy me a coffee

Stream

Stream: object

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

Factories for Stream.

iterate: {<T>(seed, f): Stream<T>; <T>(seed, hasNext, next): Stream<T>; }

iterate(seed, f): returns the infinite ordered stream seed, f(seed), f(f(seed)), …; limit it with limit or takeWhile. iterate(seed, hasNext, next): returns the ordered stream a for (t = seed; hasNext(t); t = next(t)) loop would visit.

<T>(seed, f): Stream<T>

T

T

(t) => T

Stream<T>

<T>(seed, hasNext, next): Stream<T>

T

T

(t) => boolean

(t) => T

Stream<T>

NullPointerException if a function argument is null

builder<T>(): StreamBuilder<T>

Returns a StreamBuilder that collects elements one at a time and then builds a stream of them.

T

StreamBuilder<T>

concat<T>(a, b): Stream<T>

Returns a lazy stream of all elements of a followed by all of b. Both inputs count as used; the result is parallel if either input is, and closing it closes both. Nesting concat thousands of times deep is quadratic and can overflow the call stack: use flatMap to join many streams.

T

Stream<T>

Stream<T>

Stream<T>

NullPointerException if a or b is null

empty<T>(): Stream<T>

Returns an empty stream.

T

Stream<T>

from<T>(iterable): Stream<T>

Returns a stream over any JS iterable (an addition to the reference API). Arrays are read like ofArray and this library’s collections through their own spliterators; any other iterable is read through its JS iterator (ordered, unknown size), which is closed (its finally runs) when the stream stops early or is closed.

T

Iterable<T>

Stream<T>

NullPointerException if iterable is null

generate<T>(s): Stream<T>

Returns an infinite, unordered stream of the values s() returns, called once per element pulled.

T

() => T

Stream<T>

NullPointerException if s is null

of<T>(…values): Stream<T>

Returns an ordered, sized stream of the given values (null allowed).

T

…T[]

Stream<T>

ofArray<T>(array): Stream<T>

Returns an ordered, sized stream over the array itself, without copying (an addition to the reference API). The range (0 to the length at creation) is fixed; elements are read when the terminal operation runs.

T

ArrayLike<T>

Stream<T>

NullPointerException if array is null

ofNullable<T>(t): Stream<T>

Returns a stream of t, or an empty stream when t is null or undefined.

T

T | null | undefined

Stream<T>