interface Stream<T>
A possibly infinite sequence of elements of type T. See the Stream documentation and the Stream API documentation
Companion namespace: Stream
Extends: Streamable<T>
, FastIterable<T>
Implemented by: Stream.NonEmpty<T>
Type parameters
Name | Description |
---|---|
T | the element type |
const s1 = Stream.empty<number>()
const s2 = Stream.of(1, 3, 2)
const s3 = Stream.range({ start: 10, amount: 15 })
Methods
[Symbol.iterator]
Returns a FastIterator
instance used to iterate over the values of this Iterable
.
[Symbol.iterator]
FastIterator
instance used to iterate over the values of this Iterable
.append
Returns the current stream succeeded by the given value
append
value
assumeNonEmpty
Returns the stream as a non-empty instance.
assumeNonEmpty
collect
Returns a Stream containing the resulting elements from applying the given collectFun
to each element in this Stream.
collect
collectFun
to each element in this Stream.concat
Returns a Stream containing the elements of this Stream followed by all elements produced by the others
array of StreamSources.
concat
others
array of StreamSources.contains
Returns true if the Stream contains given amount
instances of given value
, using given eq
function.
contains
amount
instances of given value
, using given eq
function.containsSlice
Returns true if this stream contains the same sequence of elements as the given source
, false otherwise.
containsSlice
source
, false otherwise.count
Returns the amount of elements in the Stream.
count
countElement
Returns the amount of elements that are equal according to the given eq
to the given value
in the Stream.
countElement
eq
to the given value
in the Stream.distinctPrevious
Returns a Stream containing non-repetitive elements of the source stream, where repetitive elements are compared using the optionally given eq
equality function.
distinctPrevious
eq
equality function.drop
Returns a stream that skips the first amount
elements of this Stream and returns the rest.
drop
amount
elements of this Stream and returns the rest.dropWhile
Returns a Stream that contains the elements of this Stream starting from the first element that does not satisfy given pred
function.
dropWhile
pred
function.elementAt
Returns the element in the Stream at the given index, or a fallback value (default undefined) otherwise.
elementAt
equals
Returns true if the sequence of elements in this stream are equal to the sequence in the other
stream according to the provided eq
function.
equals
other
stream according to the provided eq
function.every
Returns true if every element of the Stream satifies given pred
function.
every
pred
function.filter
Returns a Stream containing only those elements from this Stream for which the given pred
function returns true.
filter
pred
function returns true.filterPure
Returns a Stream containing only those elements from this Stream for which the given pred
function returns true.
filterPure
pred
function returns true.find
Returns the first element for which the given pred
function returns true, or a fallback value otherwise.
find
pred
function returns true, or a fallback value otherwise.first
Returns the first element of the Stream, or a fallback value (default undefined) if the Stream is empty.
first
flatMap
Returns a Stream consisting of the concatenation of flatMapFun
applied to each element.
flatMap
flatMapFun
applied to each element.flatZip
Returns a Stream consisting of the concatenation of flatMapFun
applied to each element, zipped with the element that was provided to the function.
flatZip
flatMapFun
applied to each element, zipped with the element that was provided to the function.fold
Returns the value resulting from applying the given the given next
function to a current state (initially the given init
value), and the next Stream value, and returning the new state. When all elements are processed, the resulting state is returned.
fold
next
function to a current state (initially the given init
value), and the next Stream value, and returning the new state. When all elements are processed, the resulting state is returned.foldStream
Returns a Stream containing the values resulting from applying the given the given next
function to a current state (initially the given init
value), and the next Stream value, and returning the new state.
foldStream
next
function to a current state (initially the given init
value), and the next Stream value, and returning the new state.forEach
Performs given function f
for each element of the Stream, using given state
as initial traversal state.
forEach
f
for each element of the Stream, using given state
as initial traversal state.forEachPure
Performs given function f
for each element of the Stream, with the optionally given args
as extra arguments.
forEachPure
f
for each element of the Stream, with the optionally given args
as extra arguments.groupBy
Returns the result of applying the valueToKey
function to calculate a key for each value, and feeding the tuple of the key and the value to the collector
reducer, and finally returning its result. If no collector is given, the default collector will return a JS multimap of the type Map<K, V[]>
.
groupBy
valueToKey
function to calculate a key for each value, and feeding the tuple of the key and the value to the collector
reducer, and finally returning its result. If no collector is given, the default collector will return a JS multimap of the type Map<K, V[]>
.indexed
Returns a Stream where each element in this Stream is paired with its index
indexed
indexOf
Returns the index of the occurrance
instance of given searchValue
in the Stream, using given eq
function, or undefined if no such value is found.
indexOf
occurrance
instance of given searchValue
in the Stream, using given eq
function, or undefined if no such value is found.indexWhere
Returns the index of the given occurrance
instance of the element in the Stream that satisfies given pred
function, or undefined if no such instance is found.
indexWhere
occurrance
instance of the element in the Stream that satisfies given pred
function, or undefined if no such instance is found.indicesOf
Returns a Stream containing the indicies of the occurrance of the given searchValue
, according to given eq
function.
indicesOf
searchValue
, according to given eq
function.indicesWhere
Returns a Stream containing the indices of the elements for which the given pred
function returns true.
indicesWhere
pred
function returns true.intersperse
Returns a Stream with all elements from the given sep
StreamSource between two elements of this Stream.
intersperse
sep
StreamSource between two elements of this Stream.join
Returns a string resulting from converting each element to string with options.valueToString
, interspersed with options.sep
, starting with options.start
and ending with options.end
.
join
options.valueToString
, interspersed with options.sep
, starting with options.start
and ending with options.end
.last
Returns the last element of the Stream, or a fallback value (default undefined) if the Stream is empty.
last
map
Returns a Stream where mapFun
is applied to each element.
map
mapFun
is applied to each element.mapPure
Returns a Stream where the given mapFun
is applied to each value in the stream, with optionally as extra arguments the given args
.
mapPure
mapFun
is applied to each value in the stream, with optionally as extra arguments the given args
.max
Returns the maximum element of the Stream according to a default compare function, or the provided otherwise
fallback value if the Stream is empty.
max
otherwise
fallback value if the Stream is empty.maxBy
Returns the maximum element of the Stream according to the provided compare
function, or the provided `otherwise fallback value if the Stream is empty.
maxBy
compare
function, or the provided `otherwise fallback value if the Stream is empty.min
Returns the mimimum element of the Stream according to a default compare function, or the provided otherwise
fallback value if the Stream is empty.
min
otherwise
fallback value if the Stream is empty.minBy
Returns the mimimum element of the Stream according to the provided compare
function, or the provided otherwise
fallback value if the Stream is empty.
minBy
compare
function, or the provided otherwise
fallback value if the Stream is empty.mkGroup
Returns a Stream starting with options.sep
, then returning the elements of this Stream interspersed with options.sep
, and ending with options.end
.
mkGroup
options.sep
, then returning the elements of this Stream interspersed with options.sep
, and ending with options.end
.partition
Returns a tuple of which the first element is the result of collecting the elements for which the given predicate
is true, and the second one the result of collecting the other elements. Own reducers can be provided as collectors, by default the values are collected into an array.
partition
predicate
is true, and the second one the result of collecting the other elements. Own reducers can be provided as collectors, by default the values are collected into an array.prepend
Returns the current stream preceded by the given value
prepend
value
reduce
Applies the given reducer
to each element in the Stream, and returns the final result.
reduce
reducer
to each element in the Stream, and returns the final result.reduceStream
Returns a Stream where the given reducer
is applied to each element in the Stream.
reduceStream
reducer
is applied to each element in the Stream.repeat
Returns a Stream that returns the elements from this Stream given amount
of times.
repeat
amount
of times.single
Returns the first element of the Stream if it only has one element, or a fallback value if the Stream does not have exactly one value.
single
some
Returns true if any element of the Stream satifies given pred
function.
some
pred
function.splitOn
Returns a Stream of collections of Stream elements, where each collection is filled with elements of this Stream up to the next element that equals given sepElem
according to the given eq
function.
splitOn
sepElem
according to the given eq
function.splitOnSlice
Returns a Stream of collections of Stream elements, where each collection is filled with elements of this Stream up to the next sequence of elements that equal the given sepSeq
sequence of elements according to the given eq
function.
splitOnSlice
sepSeq
sequence of elements according to the given eq
function.splitWhere
Returns a Stream of collections of Stream elements, where each collection is filled with elements of this Stream up to the next element that satisfies give function pred
.
splitWhere
pred
.stream
Returns a stream of elements of type T.
stream
take
Returns a stream that contains the elements of this Stream up to a maximum of amount
elements.
take
amount
elements.takeWhile
Returns a Stream that contains the elements of this Stream up to the first element that does not satisfy given pred
function.
takeWhile
pred
function.toArray
Returns an Array containing all elements in the Stream.
toArray
toJSON
Returns a JSON representation of the Stream.
toJSON
toString
Returns a string representation of the Stream.
toString
transform
Returns a Stream consisting of the concatenation of StreamSource elements resulting from applying the given reducer
to each element.
transform
reducer
to each element.window
Returns a Stream containing windows
of windowSize
consecutive elements of the source stream, with each window starting skipAmount
elements after the previous one.
window
windows
of windowSize
consecutive elements of the source stream, with each window starting skipAmount
elements after the previous one.withOnly
Returns a Stream containing only those elements that are in the given values
array.
withOnly
values
array.without
Returns a Stream containing all elements except the elements in the given values
array.
without
values
array.