@rimbu/stream
Version:
Efficient structure representing a sequence of elements, with powerful operations for TypeScript
191 lines (190 loc) • 9.68 kB
text/typescript
import { AsyncOptLazy, Eq, TraverseState, type ArrayNonEmpty, type AsyncCollectFun, type MaybePromise, type ToJSON } from '@rimbu/common';
import { AsyncReducer, AsyncTransformer, type AsyncFastIterator, type AsyncStream, type AsyncStreamSource } from '@rimbu/stream/async';
import { type AsyncStreamConstructors } from '@rimbu/stream/async-custom';
export declare abstract class AsyncStreamBase<T> implements AsyncStream<T> {
abstract [Symbol.asyncIterator](): AsyncFastIterator<T>;
asyncStream(): this;
equals(other: AsyncStreamSource<T>, options?: {
eq?: Eq<T>;
negate?: boolean;
}): Promise<boolean>;
assumeNonEmpty(): AsyncStream.NonEmpty<T>;
asNormal(): AsyncStream<T>;
prepend(value: AsyncOptLazy<T>): AsyncStream.NonEmpty<T>;
append(value: AsyncOptLazy<T>): AsyncStream.NonEmpty<T>;
forEach(f: (value: T, index: number, halt: () => void) => MaybePromise<void>, options?: {
state?: TraverseState;
}): Promise<void>;
forEachPure<A extends readonly unknown[]>(f: (value: T, ...args: A) => MaybePromise<void>, ...args: A): Promise<void>;
indexed(options?: {
startIndex?: number;
}): AsyncStream<[number, T]>;
filter(pred: (value: T, index: number, halt: () => void) => MaybePromise<boolean>, options?: {
negate?: boolean | undefined;
}): any;
filterPure<A extends readonly unknown[]>(options: {
pred: (value: T, ...args: A) => MaybePromise<boolean>;
negate?: boolean | undefined;
}, ...args: A): any;
withOnly<F extends T>(values: F[]): AsyncStream<F>;
without<F extends T>(values: F[]): any;
map<T2>(mapFun: (value: T, index: number) => MaybePromise<T2>): AsyncStream<T2>;
mapPure<T2, A extends readonly unknown[]>(mapFun: (value: T, ...args: A) => MaybePromise<T2>, ...args: A): AsyncStream<T2>;
collect<R>(collectFun: AsyncCollectFun<T, R>): AsyncStream<R>;
flatMap<T2>(flatMapFun: (value: T, index: number, halt: () => void) => AsyncStreamSource<T2>): AsyncStream<T2>;
flatZip<T2>(flatMapFun: (value: T, index: number, halt: () => void) => AsyncStreamSource<T2>): AsyncStream<[T, T2]>;
transform<R>(transformer: AsyncTransformer.Accept<T, R>): AsyncStream<R>;
first<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
last<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
single<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
count(): Promise<number>;
countElement(value: T, options?: {
eq?: Eq<T>;
negate?: boolean;
}): Promise<number>;
find<O>(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
occurrance?: number | undefined;
negate?: boolean | undefined;
otherwise?: AsyncOptLazy<O>;
}): Promise<T | O>;
elementAt<O>(index: number, otherwise?: AsyncOptLazy<O>): Promise<T | O>;
indicesWhere(pred: (value: T) => MaybePromise<boolean>, options?: {
negate?: boolean;
}): AsyncStream<number>;
indicesOf(searchValue: T, options?: {
eq?: Eq<T>;
negate?: boolean;
}): AsyncStream<number>;
indexWhere(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
occurrance?: number;
negate?: boolean;
}): Promise<number | undefined>;
indexOf(searchValue: T, options?: {
occurrance?: number | undefined;
eq?: Eq<T> | undefined;
negate?: boolean | undefined;
}): Promise<number | undefined>;
some(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean;
}): Promise<boolean>;
every(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean;
}): Promise<boolean>;
contains(searchValue: T, options?: {
amount?: number;
eq?: Eq<T>;
negate?: boolean;
}): Promise<boolean>;
containsSlice(source: AsyncStreamSource.NonEmpty<T>, options?: {
eq?: Eq<T>;
amount?: number;
}): Promise<boolean>;
takeWhile(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean;
}): AsyncStream<T>;
dropWhile(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean;
}): AsyncStream<T>;
take(amount: number): AsyncStream<T>;
drop(amount: number): AsyncStream<T>;
repeat(amount?: number): AsyncStream<T>;
concat(...others: ArrayNonEmpty<AsyncStreamSource<T>>): any;
min<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
minBy<O>(compare: (v1: T, v2: T) => number, otherwise?: AsyncOptLazy<O>): Promise<T | O>;
max<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
maxBy<O>(compare: (v1: T, v2: T) => number, otherwise?: AsyncOptLazy<O>): Promise<T | O>;
intersperse(sep: AsyncStreamSource<T>): AsyncStream<T>;
join({ sep, start, end, valueToString, ifEmpty, }?: {
sep?: string | undefined;
start?: string | undefined;
end?: string | undefined;
valueToString?: StringConstructor | undefined;
ifEmpty?: undefined;
}): Promise<string>;
mkGroup({ sep, start, end, }?: {
sep?: AsyncStreamSource<T>;
start?: AsyncStreamSource<T>;
end?: AsyncStreamSource<T>;
}): any;
splitWhere<R>(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncStream<R>;
splitOn<R>(sepElem: T, options?: {
eq?: Eq<T> | undefined;
negate?: boolean | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncStream<R>;
splitOnSlice<R>(sepSlice: AsyncStreamSource<T>, options?: {
eq?: Eq<T> | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncStream<R>;
distinctPrevious(options?: {
eq?: Eq<T> | undefined;
negate?: boolean | undefined;
}): AsyncStream<T>;
window<R>(windowSize: number, options?: {
skipAmount?: number | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncStream<R>;
partition(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
collectorTrue?: any;
collectorFalse?: any;
}): Promise<[any, any]>;
groupBy<K, R>(valueToKey: (value: T, index: number) => MaybePromise<K>, options?: {
collector?: AsyncReducer.Accept<readonly [K, T], R> | undefined;
}): Promise<R>;
fold<R>(init: AsyncOptLazy<R>, next: (current: R, value: T, index: number, halt: () => void) => MaybePromise<R>): Promise<R>;
foldStream<R>(init: AsyncOptLazy<R>, next: (current: R, value: T, index: number, halt: () => void) => MaybePromise<R>): AsyncStream<R>;
reduce<const S extends AsyncReducer.CombineShape<T>>(shape: S & AsyncReducer.CombineShape<T>): Promise<AsyncReducer.CombineResult<S>>;
reduceStream<const S extends AsyncReducer.CombineShape<T>>(shape: S & AsyncReducer.CombineShape<T>): AsyncStream<AsyncReducer.CombineResult<S>>;
toArray(): Promise<T[]>;
toString(): string;
toJSON(): Promise<ToJSON<T[], 'AsyncStream'>>;
}
export declare class AsyncFromStream<T> extends AsyncStreamBase<T> {
[Symbol.asyncIterator]: () => AsyncFastIterator<T>;
constructor(createIterator: () => AsyncFastIterator<T>);
}
export declare class AsyncTransformerStream<T, R = T> extends AsyncStreamBase<R> {
readonly source: AsyncStream<T>;
readonly transformer: AsyncTransformer.Accept<T, R>;
constructor(source: AsyncStream<T>, transformer: AsyncTransformer.Accept<T, R>);
[Symbol.asyncIterator](): AsyncFastIterator<R>;
}
export declare class AsyncOfStream<T> extends AsyncStreamBase<T> {
readonly values: ArrayNonEmpty<AsyncOptLazy<T>>;
constructor(values: ArrayNonEmpty<AsyncOptLazy<T>>);
[Symbol.asyncIterator](): AsyncFastIterator<T>;
}
export declare function isAsyncStream(obj: any): obj is AsyncStream<any>;
export declare class FromSource<T> extends AsyncStreamBase<T> {
readonly source: AsyncStreamSource<T>;
readonly close?: (() => MaybePromise<void>) | undefined;
constructor(source: AsyncStreamSource<T>, close?: (() => MaybePromise<void>) | undefined);
[Symbol.asyncIterator](): AsyncFastIterator<T>;
}
export declare class FromResource<T, R> extends AsyncStreamBase<T> {
readonly open: () => MaybePromise<R>;
readonly createSource: (resource: R) => MaybePromise<AsyncStreamSource<T>>;
readonly close?: ((resource: R) => MaybePromise<void>) | undefined;
constructor(open: () => MaybePromise<R>, createSource: (resource: R) => MaybePromise<AsyncStreamSource<T>>, close?: ((resource: R) => MaybePromise<void>) | undefined);
[Symbol.asyncIterator](): AsyncFastIterator<T>;
}
export declare const emptyAsyncStream: AsyncStream<any>;
export declare function isEmptyAsyncStreamSourceInstance(source: AsyncStreamSource<any>): boolean;
export declare function asyncStreamSourceToIterator<T>(source: AsyncStreamSource<T>, close?: () => MaybePromise<void>): AsyncFastIterator<T>;
export declare const fromAsyncStreamSource: {
<T>(source: AsyncStreamSource.NonEmpty<T>): AsyncStream.NonEmpty<T>;
<T>(source: AsyncStreamSource<T>): AsyncStream<T>;
};
declare const asyncStreamSourceHelpers: {
fromAsyncStreamSource: {
<T>(source: AsyncStreamSource.NonEmpty<T>): AsyncStream.NonEmpty<T>;
<T>(source: AsyncStreamSource<T>): AsyncStream<T>;
};
isEmptyAsyncStreamSourceInstance: typeof isEmptyAsyncStreamSourceInstance;
};
export type AsyncStreamSourceHelpers = typeof asyncStreamSourceHelpers;
export declare const AsyncStreamConstructorsImpl: AsyncStreamConstructors;
export {};