Skip to main content
Module

x/rimbu/mod.ts>AsyncStream.NonEmpty

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
interface AsyncStream.NonEmpty
implements AsyncStream<T>
import { type AsyncStream } from "https://deno.land/x/rimbu@0.14.0/mod.ts";
const { NonEmpty } = AsyncStream;

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

Examples

Example 1

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

Methods

asNormal(): AsyncStream<T>

Returns this collection typed as a 'possibly empty' collection.

asyncStream(): this

Returns a non-empty async stream of elements of type T.

indexed(startIndex?: number): AsyncStream.NonEmpty<[number, T]>

Returns a non-empty AsyncStream where each element in this stream is paired with its index

map<T2>(mapFun: (value: T, index: number) => MaybePromise<T2>): AsyncStream.NonEmpty<T2>

Returns a non-empty AsyncStream where mapFun is applied to each element.

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

Returns a non-empty AsyncStream 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) => AsyncStreamSource.NonEmpty<T2>): AsyncStream.NonEmpty<T2>

Returns an AsyncStream consisting of the concatenation of flatMapFun applied to each element.

flatMap<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => AsyncStreamSource<T2>
): AsyncStream<T2>
flatZip<T2>(flatMapFun: (value: T, index: number) => AsyncStreamSource.NonEmpty<T2>): AsyncStream.NonEmpty<[T, T2]>

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

flatZip<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => AsyncStreamSource<T2>
): AsyncStream<[T, T2]>
transform<R>(transformer: AsyncTransformer.NonEmpty<T, R>): AsyncStream.NonEmpty<R>

Returns an AsyncStream consisting of the concatenation of AsyncStreamSource elements resulting from applying the given reducer to each element.

transform<R>(transformer: AsyncTransformer<T, R>): AsyncStream<R>
first(): Promise<T>

Returns the first element of the AsyncStream.

last(): Promise<T>

Returns the last element of the AsyncStream.

repeat(amount?: number): AsyncStream.NonEmpty<T>

Returns a non-empty AsyncStream that returns the elements from this stream given amount of times.

concat<T2 = T>(...others: ArrayNonEmpty<AsyncStreamSource<T>>): AsyncStream.NonEmpty<T | T2>

Returns a non-empty AsyncStream containing the elements of this stream followed by all elements produced by the others array of AsyncStreamSources.

min(): Promise<T>

Returns the mimimum element of the AsyncStream according to a default compare function.

minBy(compare: (v1: T, v2: T) => number): Promise<T>

Returns the mimimum element of the AsyncStream according to the provided compare function.

max(): Promise<T>

Returns the maximum element of the AsyncStream according to a default compare function.

maxBy(compare: (v1: T, v2: T) => number): Promise<T>

Returns the maximum element of the AsyncStream according to the provided compare function.

Returns a non-empty AsyncStream with all elements from the given sep AsyncStreamSource between two elements of this stream.

mkGroup(options: { sep?: AsyncStreamSource<T>; start?: AsyncStreamSource<T>; end?: AsyncStreamSource<T>; }): AsyncStream.NonEmpty<T>

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

distinctPrevious(eq?: Eq<T>): AsyncStream.NonEmpty<T>

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

foldStream<R>(init: AsyncOptLazy<R>, next: (
current: R,
value: T,
index: number,
) => MaybePromise<R>
): AsyncStream.NonEmpty<R>

Returns an AsyncStream 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<R>(init: AsyncOptLazy<R>, next: (
current: R,
value: T,
index: number,
halt: () => void,
) => MaybePromise<R>
): AsyncStream<R>
toArray(): Promise<ArrayNonEmpty<T>>

Returns a non-empty Array containing all elements in the AsyncStream.

Examples

Example 1

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

Methods

asNormal(): AsyncStream<T>

Returns this collection typed as a 'possibly empty' collection.

asyncStream(): this

Returns a non-empty async stream of elements of type T.

indexed(startIndex?: number): AsyncStream.NonEmpty<[number, T]>

Returns a non-empty AsyncStream where each element in this stream is paired with its index

map<T2>(mapFun: (value: T, index: number) => MaybePromise<T2>): AsyncStream.NonEmpty<T2>

Returns a non-empty AsyncStream where mapFun is applied to each element.

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

Returns a non-empty AsyncStream 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) => AsyncStreamSource.NonEmpty<T2>): AsyncStream.NonEmpty<T2>

Returns an AsyncStream consisting of the concatenation of flatMapFun applied to each element.

flatMap<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => AsyncStreamSource<T2>
): AsyncStream<T2>
flatZip<T2>(flatMapFun: (value: T, index: number) => AsyncStreamSource.NonEmpty<T2>): AsyncStream.NonEmpty<[T, T2]>

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

flatZip<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => AsyncStreamSource<T2>
): AsyncStream<[T, T2]>
transform<R>(transformer: AsyncTransformer.NonEmpty<T, R>): AsyncStream.NonEmpty<R>

Returns an AsyncStream consisting of the concatenation of AsyncStreamSource elements resulting from applying the given reducer to each element.

transform<R>(transformer: AsyncTransformer<T, R>): AsyncStream<R>
first(): Promise<T>

Returns the first element of the AsyncStream.

last(): Promise<T>

Returns the last element of the AsyncStream.

repeat(amount?: number): AsyncStream.NonEmpty<T>

Returns a non-empty AsyncStream that returns the elements from this stream given amount of times.

concat<T2 = T>(...others: ArrayNonEmpty<AsyncStreamSource<T>>): AsyncStream.NonEmpty<T | T2>

Returns a non-empty AsyncStream containing the elements of this stream followed by all elements produced by the others array of AsyncStreamSources.

min(): Promise<T>

Returns the mimimum element of the AsyncStream according to a default compare function.

minBy(compare: (v1: T, v2: T) => number): Promise<T>

Returns the mimimum element of the AsyncStream according to the provided compare function.

max(): Promise<T>

Returns the maximum element of the AsyncStream according to a default compare function.

maxBy(compare: (v1: T, v2: T) => number): Promise<T>

Returns the maximum element of the AsyncStream according to the provided compare function.

Returns a non-empty AsyncStream with all elements from the given sep AsyncStreamSource between two elements of this stream.

mkGroup(options: { sep?: AsyncStreamSource<T>; start?: AsyncStreamSource<T>; end?: AsyncStreamSource<T>; }): AsyncStream.NonEmpty<T>

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

distinctPrevious(eq?: Eq<T>): AsyncStream.NonEmpty<T>

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

foldStream<R>(init: AsyncOptLazy<R>, next: (
current: R,
value: T,
index: number,
) => MaybePromise<R>
): AsyncStream.NonEmpty<R>

Returns an AsyncStream 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<R>(init: AsyncOptLazy<R>, next: (
current: R,
value: T,
index: number,
halt: () => void,
) => MaybePromise<R>
): AsyncStream<R>
toArray(): Promise<ArrayNonEmpty<T>>

Returns a non-empty Array containing all elements in the AsyncStream.