Skip to main content
Module

x/rimbu/mod.ts>Stream.NonEmpty

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

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

Methods

asNormal(): Stream<T>

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

stream(): this

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

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

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

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

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

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

Returns a non-empty tream 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) => StreamSource.NonEmpty<T2>): Stream.NonEmpty<T2>

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

flatMap<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => StreamSource<T2>
): Stream<T2>
flatZip<T2>(flatMapFun: (value: T, index: number) => StreamSource.NonEmpty<T2>): Stream.NonEmpty<[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.

flatZip<T2>(flatMapFun: (
value: T,
index: number,
halt: () => void,
) => StreamSource<T2>
): Stream<[T, T2]>
transform<R>(transformer: Transformer.NonEmpty<T, R>): Stream.NonEmpty<R>

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

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

Returns the first element of the Stream.

last(): T

Returns the last element of the Stream.

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

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

concat<T2 = T>(...others: ArrayNonEmpty<StreamSource<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.

min(): T

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

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

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

max(): T

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

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

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

intersperse(sep: StreamSource<T>): Stream.NonEmpty<T>

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

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

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

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

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

foldStream<R>(init: OptLazy<R>, next: (
current: R,
value: T,
index: number,
) => R
): Stream.NonEmpty<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.

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

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