Determines the number of elements in this stream.
Returns the elements of the stream that meet the condition specified in a callback function. The function is called when the resulting stream elements are actually accessed, so accessing the resulting stream multiple times means the function is also called multiple times for each element of the stream.
Returns the value of the first element in the stream that meets the condition, or undefined
if there is no such element.
Returns the index of the first element in the stream that meets the condition, or -1
if there is no such element.
This method calls predicate
once for each element of the stream, in ascending
order, until it finds one where predicate
returns a value which is coercible to the
Boolean value true
.
Returns a new stream with all sub-stream or sub-array elements concatenated into it recursively up to the specified depth.
Optional
depth: DThe maximum recursion depth. Defaults to 1.
Performs the specified action for each element in the stream.
Function called once for each element in the stream.
Returns the first element in the stream, or undefined
if the stream is empty.
Determines whether the stream includes a certain element, returning true
or false
as appropriate.
The element to search for.
Returns the index of the first occurrence of a value in the stream, or -1 if it is not present.
The value to locate in the array.
Optional
fromIndex: numberThe stream index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Determines whether this stream contains no elements.
Returns an iterator for this stream. This is the same as calling the Symbol.iterator
function property.
Adds all elements of the stream into a string, separated by the specified separator string.
Optional
separator: stringA string used to separate one element of the stream from the next in the resulting string. If omitted, the steam elements are separated with a comma.
Returns a stream that yields the results of calling the specified callback function on each element of the stream. The function is called when the resulting stream elements are actually accessed, so accessing the resulting stream multiple times means the function is also called multiple times for each element of the stream.
Calls the specified callback function for all elements in the stream. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Calls the specified callback function for all elements in the stream, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Determines whether any member of the stream satisfies the specified test.
This method calls the predicate function for each element in the stream until the
predicate returns a value which is coercible to the Boolean value true
, or until the end
of the stream.
Collects all elements of this stream into an array.
Collects all elements of this stream into a Set.
Returns a string representation of a stream.
A stream is a read-only sequence of values. While the contents of an array can be accessed both sequentially and randomly (via index), a stream allows only sequential access.
The advantage of this is that a stream can be evaluated lazily, so it does not require to store intermediate values. This can boost performance when a large sequence is processed via filtering, mapping etc. and accessed at most once. However, lazy evaluation means that all processing is repeated when you access the sequence multiple times; in such a case, it may be better to store the resulting sequence into an array.