Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/core/menu/menu.ts>Stream

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
namespace Stream
Re-export
import { Stream } from "https://deno.land/x/rimbu@1.1.0/core/menu/menu.ts";

Interfaces

A non-empty and possibly infinite sequence of elements of type T. See the Stream documentation and the Stream API documentation

interface Stream
implements FastIterable<T>, Streamable<T>
Re-export
import { type Stream } from "https://deno.land/x/rimbu@1.1.0/core/menu/menu.ts";

A possibly infinite sequence of elements of type T. See the Stream documentation and the Stream API documentation

Examples

Example 1

const s1 = Stream.empty<number>()
const s2 = Stream.of(1, 3, 2)
const s3 = Stream.range({ start: 10, amount: 15 })

Methods

stream(): this

Returns a stream of elements of type T.

equals(other: StreamSource<T>, options?: { eq?: Eq<T>; negate?: boolean; }): boolean

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.

assumeNonEmpty(): Stream.NonEmpty<T>

Returns the stream as a non-empty instance.

prepend(value: OptLazy<T>): Stream.NonEmpty<T>

Returns the current stream preceded by the given value

append(value: OptLazy<T>): Stream.NonEmpty<T>

Returns the current stream succeeded by the given value

forEach(f: (
value: T,
index: number,
halt: () => void,
) => void
, options?: { state?: TraverseState; }
): void

Performs given function f for each element of the Stream, using given state as initial traversal state.

forEachPure<A extends readonly unknown[]>(f: (value: T, ...args: A) => void, ...args: A): void

Performs given function f for each element of the Stream, with the optionally given args as extra arguments.

indexed(options?: { startIndex?: number; }): Stream<[number, T]>

Returns a Stream where each element in this Stream is paired with its index

map<T2>(mapFun: (value: T, index: number) => T2): Stream<T2>

Returns a Stream where mapFun is applied to each element.

mapPure<T2, A extends readonly unknown[]>(mapFun: (value: T, ...args: A) => T2, ...args: A): Stream<T2>

Returns a Stream where the given mapFun is applied to each value in the stream, with optionally as extra arguments the given args.

flatMap<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => StreamSource<T2>
): Stream<T2>

Returns a Stream consisting of the concatenation of flatMapFun applied to each element.

flatZip<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => StreamSource<T2>
): Stream<[T, T2]>

Returns a Stream consisting of the concatenation of flatMapFun applied to each element, zipped with the element that was provided to the function.

transform<R>(transformer: Transformer<T, R>): Stream<R>

Returns a Stream consisting of the concatenation of StreamSource elements resulting from applying the given reducer to each element.

filter(pred: (
value: T,
index: number,
halt: () => void,
) => boolean
, options?: { negate?: boolean; }
): Stream<T>

Returns a Stream containing only those elements from this Stream for which the given pred function returns true.

filterPure<A extends readonly unknown[]>(options: { pred: (value: T, ...args: A) => boolean; negate?: boolean; }, ...args: A): Stream<T>

Returns a Stream containing only those elements from this Stream for which the given pred function returns true.

collect<R>(collectFun: CollectFun<T, R>): Stream<R>

Returns a Stream containing the resulting elements from applying the given collectFun to each element in this Stream.

first(): T | undefined

Returns the first element of the Stream, or a fallback value (default undefined) if the Stream is empty.

first<O>(otherwise: OptLazy<O>): T | O
last(): T | undefined

Returns the last element of the Stream, or a fallback value (default undefined) if the Stream is empty.

last<O>(otherwise: OptLazy<O>): T | O
single(): T | undefined

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<O>(otherwise: OptLazy<O>): T | O
count(): number

Returns the amount of elements in the Stream.

countElement(value: T, options?: { eq?: Eq<T>; negate?: boolean; }): number

Returns the amount of elements that are equal according to the given eq to the given value in the Stream.

find<O>(pred: (value: T, index: number) => boolean, options: { occurrance?: number; negate?: boolean; otherwise: OptLazy<O>; }): T | O

Returns the first element for which the given pred function returns true, or a fallback value otherwise.

find(pred: (value: T, index: number) => boolean, options?: { occurrance?: number; negate?: boolean; otherwise?: undefined; }): T | undefined
elementAt(index: number): T | undefined

Returns the element in the Stream at the given index, or a fallback value (default undefined) otherwise.

elementAt<O>(index: number, otherwise: OptLazy<O>): T | O
indicesWhere(pred: (value: T) => boolean, options?: { negate?: boolean; }): Stream<number>

Returns a Stream containing the indices of the elements for which the given pred function returns true.

indicesOf(searchValue: T, options?: { eq?: Eq<T>; negate?: boolean; }): Stream<number>

Returns a Stream containing the indicies of the occurrance of the given searchValue, according to given eq function.

indexWhere(pred: (value: T, index: number) => boolean, options?: { occurrance?: number; negate?: boolean; }): number | undefined

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.

indexOf(searchValue: T, options?: { occurrance?: number; eq?: Eq<T>; negate?: boolean; }): number | undefined

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.

some(pred: (value: T, index: number) => boolean, options?: { negate?: boolean; }): boolean

Returns true if any element of the Stream satifies given pred function.

every(pred: (value: T, index: number) => boolean, options?: { negate?: boolean; }): boolean

Returns true if every element of the Stream satifies given pred function.

contains(value: T, options?: { amount?: number; eq?: Eq<T>; negate?: boolean; }): boolean

Returns true if the Stream contains given amount instances of given value, using given eq function.

containsSlice(source: StreamSource.NonEmpty<T>, options?: { eq?: Eq<T>; }): boolean

Returns true if this stream contains the same sequence of elements as the given source, false otherwise.

takeWhile(pred: (value: T, index: number) => boolean, options?: { negate?: boolean; }): Stream<T>

Returns a Stream that contains the elements of this Stream up to the first element that does not satisfy given pred function.

dropWhile(pred: (value: T, index: number) => boolean, options?: { negate?: boolean; }): Stream<T>

Returns a Stream that contains the elements of this Stream starting from the first element that does not satisfy given pred function.

take(amount: number): Stream<T>

Returns a stream that contains the elements of this Stream up to a maximum of amount elements.

drop(amount: number): Stream<T>

Returns a stream that skips the first amount elements of this Stream and returns the rest.

repeat(amount?: number): Stream<T>

Returns a Stream that returns the elements from this Stream given amount of times.

concat<T2 = T>(...others: ArrayNonEmpty<StreamSource.NonEmpty<T2>>): Stream.NonEmpty<T | T2>

Returns a Stream containing the elements of this Stream followed by all elements produced by the others array of StreamSources.

concat<T2 = T>(...others: ArrayNonEmpty<StreamSource<T2>>): Stream<T | T2>
min(): T | undefined

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<O>(otherwise: OptLazy<O>): T | O
minBy(compare: (v1: T, v2: T) => number): T | undefined

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<O>(compare: (v1: T, v2: T) => number, otherwise: OptLazy<O>): T | O
max(): T | undefined

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<O>(otherwise: OptLazy<O>): T | O
maxBy(compare: (v1: T, v2: T) => number): T | undefined

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<O>(compare: (v1: T, v2: T) => number, otherwise: OptLazy<O>): T | O
intersperse(sep: StreamSource<T>): Stream<T>

Returns a Stream with all elements from the given sep StreamSource between two elements of this Stream.

join(options?: { sep?: string | undefined; start?: string | undefined; end?: string | undefined; valueToString?: ((value: T) => string) | undefined; ifEmpty?: string | undefined; }): string

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.

mkGroup(options: { sep?: StreamSource<T>; start?: StreamSource<T>; end?: StreamSource<T>; }): Stream<T>

Returns a Stream starting with options.sep, then returning the elements of this Stream interspersed with options.sep, and ending with options.end.

splitWhere<R>(pred: (value: T, index: number) => boolean, options: { negate?: boolean; collector: Reducer<T, R>; }): Stream<R>

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: (value: T, index: number) => boolean, options?: { negate?: boolean; collector?: undefined; }): Stream<T[]>
splitOn<R, T2 extends T = T>(sepElem: T2, options: { eq?: Eq<T2>; negate?: boolean; collector: Reducer<T, R>; }): Stream<T[]>

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: T, options?: { eq?: Eq<T>; negate?: boolean; collector?: undefined; }): Stream<T[]>
splitOnSeq<R, T2 extends T = T>(sepSeq: StreamSource<T2>, options: { eq?: Eq<T2>; collector: Reducer<T, R>; }): Stream<R>

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.

splitOnSeq(sepSeq: StreamSource<T>, options?: { eq?: Eq<T>; collector?: undefined; }): Stream<T[]>
distinctPrevious(options?: { eq?: Eq<T>; negate?: boolean; }): Stream<T>

Returns a Stream containing non-repetitive elements of the source stream, where repetitive elements are compared using the optionally given eq equality function.

window<R>(windowSize: number, options: { skipAmount?: number; collector: Reducer<T, R>; }): Stream<R>

Returns a Stream containing windows of windowSize consecutive elements of the source stream, with each window starting skipAmount elements after the previous one.

window(windowSize: number, options?: { skipAmount?: number; collector?: undefined; }): Stream<T[]>
fold<R>(init: OptLazy<R>, next: (
current: R,
value: T,
index: number,
halt: () => void,
) => R
): R

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.

foldStream<R>(init: OptLazy<R>, next: (
current: R,
value: T,
index: number,
halt: () => void,
) => R
): Stream<R>

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.

reduce<R>(reducer: Reducer<T, R>): R

Applies the given reducer to each element in the Stream, and returns the final result.

reduce<S extends Reducer.CombineShape<T>>(shape: S & Reducer.CombineShape<T>): Reducer.CombineResult<S>

Applies the given combined Reducer to each element in the Stream, and returns the final result.

reduceStream<R>(reducer: Reducer<T, R>): Stream<R>

Returns a Stream where the given reducer is applied to each element in the Stream.

reduceStream<S extends Reducer.CombineShape<T>>(shape: S & Reducer.CombineShape<T>): Stream<Reducer.CombineResult<S>>

Returns a Stream where the given shape containing Reducers is applied to each element in the stream.

toArray(): T[]

Returns an Array containing all elements in the Stream.

toString(): string

Returns a string representation of the Stream.

toJSON(): ToJSON<T[], "Stream">

Returns a JSON representation of the Stream.

variable Stream
Re-export
import { Stream } from "https://deno.land/x/rimbu@1.1.0/core/menu/menu.ts";

type

StreamConstructors