Abstract
Static
allGenerates an infinite stream of integers, starting with start
(which defaults to 0).
In other words, this produces the interval [start, start + 1, ...)
.
The returned stream is infinite, truncate the stream accordingly by using for example take()
,
or break in a for...of
loop.
Optional
start: numberthe start value
Static
concatStatic
emptyStatic
entriesStatic
enumerateStatic
fromWraps an iterable into a stream.
The returned stream can be iterated multiple times if the original iterable can also be iterated multiple times (some iterables, like generators, do not support repeated iteration).
Wraps an iterable into a stream.
The returned stream can be iterated multiple times if the original iterable can also be iterated multiple times (some iterables, like generators, do not support repeated iteration).
Static
generateStatic
integersGenerates a stream of count
integers, starting with 0.
In other words, this produces the interval [0, 1, ..., count)
.
the number of integers to produce
Generates a stream of count
integers, starting with the provided start
index.
In other words, this produces the interval [start +0, start +1, ..., start +count)
.
the start value
the number of integers to produce
Static
keysStatic
ofStatic
valuesStatic
zipCreates a new stream by zipping the elements of the given iterables. The iterables will be iterated in parallel, so each element of the new stream will be a tuple with one element per iterable.
The stream stops when the shortest of the given iterables has ended.
the iterables to concatenate
Static
zipCreates a new stream by zipping the elements of the given iterables. The iterables will be iterated in parallel, so each element of the new stream will be a tuple with one element per iterable.
The stream stops when the longest of the given iterables has ended. When individual iterables are exhausted, their tuple items are set to undefined.
the iterables to zip
Abstract
[iterator]Returns a stream over the original items grouped into chunks of size chunkSize
.
Up to chunkSize
consecutive elements will be gathered into an array and then
returned by the stream.
All arrays, except for the last one, will be of length chunkSize
.
the maximum chunk size
Chains the given iterables after this
(see static concat
function for details).
the iterables to concatenate
Determines if all items in the stream fulfill the given predicate.
NOTE: Trivially returns true
if the stream is empty.
Returns true
if all item in the stream fulfills the given predicate, false
otherwise.
Returns a stream that filters the input by predicate
. Only items for which predicate(item)
returns true will be produced by the stream.
Returns a stream that filters the input by predicate
. Only items for which predicate(item)
returns true will be produced by the stream.
A function that returns true
if the item should be part of the returned stream.
Searches the elements in this stream for an item for which the predicate
returns true
. Returns the item on success or undefined
if no item was found.
Searches the elements in this stream for an item for which the predicate
returns true
. Returns the item on success or undefined
if no item was found.
Returns a stream that groups adjacent elements for which the predicate returns true
into arrays.
This is different from groupBy
because it allows arbitrary conditions for grouping.
However, only elements next to each other can belong to a group.
A new group is started whenever an element is encountered that does not belong to the current group.
Groups items together for which keyFunc
returns the same value.
The keyFunc
function should generate keys that are supported by
JavaScript's Map
type.
NOTE: This function reads the entire stream into memory and stores items in an internal map, which may be inefficient for very large datasets.
Returns the last item in this stream, or undefined if this stream is empty.
NOTE: This iterates over the entire stream in order to find the last element. Be aware of the performance implications: the function should not be called repeatedly (cache the result instead) and you should ensure that your stream is finite.
Returns the largest stream item according to the given compareFunc
.
If multiple candidates for the largest element compare equal to each other,
the first of those items (according to the stream order) will be returned.
the largest item or undefined
if the stream is empty.
Like max()
, but compares keys derived from the stream's items instead of the items themselves.
The item with the largest key will be returned (or undefined if the stream is empty).
Given an item, returns a sort key for comparison during sorting. This function should be fast, because it will be invoked at least once for every element.
Optional
compareFunc: (left: U, right: U) => numberGiven two keys derived by keyFunc
, returns < 0
if left < right
, > 0
if left > right
and 0
otherwise.
When not specified, keys are compared using standard <
and >
(which might be useless,
e.g. when keys are objects or arrays).
the largest item or undefined
if the stream is empty.
Invokes the reduceFunc
for every element of the stream in order to provide a single return value.
Works exactly like Array's reduce
function, with the exception that no source array is passed.
Invokes the reduceFunc
for every element of the stream in order to provide a single return value.
Works exactly like Array's reduce
function, with the exception that no source array is passed.
Returns a stream that skips elements while the predicate returns true
.
Once the predicate returns false
, all the following items will be included
in the returned stream.
A predicate determining if items shall be skipped. Once the predicate
returns false
, all remaining items are included in the returned stream.
Returns a stream that has all its elements sorted according to the given compareFunc
.
The comparison function is optional, the Array sort behavior will be used by default when
the function is omitted. The function must behave as expected by the Array.sort()
method.
See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
NOTE: This function reads the entire stream into memory and stores all elements in an array to be able to sort it. This may be inefficient for very large datasets.
Like sort()
, but sorts by comparing keys derived from the stream's items.
NOTE: This function reads the entire stream into memory and stores all elements in an array to be able to sort it. This may be inefficient for very large datasets.
Given an item, returns a sort key for comparison during sorting. This function should be fast, because it will be invoked at least once for every element.
Optional
compareFunc: (leftKey: U, rightKey: U) => numberGiven two keys derived by keyFunc
, returns < 0
if left < right
, > 0
if right > left
and 0
otherwise.
When not specified, keys are compared using standard <
and >
(which might be useless,
e.g. when keys are objects or arrays).
A new stream of sorted elements.
Returns a stream over the input that produces values while the predicate
returns true. The stream will be cut off when the predicate returns false
for the first time.
Determines when including items in the returned stream shall be stopped.
Gathers the elements of this stream into a map. The elements must be [key, value] pairs.
Note: elements are inserted into the map in the order they occur in the stream. Iterating over the map will yield the same order because maps maintain their insertion order.
Gathers all elements of this stream into an object. The elements must be [key, value] pairs, and the keys must be strings, symbols or numbers.
Returns a stream that consists of all elements of this stream, with duplicates removed. The relative order of the remaining elements is preserved.
NOTE: This function reads the entire stream into memory and stores all elements in a Set for de-duplication. This may be inefficient for very large datasets.
A new stream with unique items.
Zips the given iterables with this
with the zipLongest algorithm (see static
zipLongest
function for details).
The length of the resulting stream is the maximum length of all iterables, with empty
positions filled with undefined
.
a series of iterables who's items will be zipped next to the items of this
.
Zips the given iterables with this
(see static zip
function for details).
The length of the resulting stream is the minimum length of all iterables.
a series of iterables who's items will be zipped next to the items of this
.
A stream is an iterable, lazy sequence of elements.