import { Token } from '@rimbu/base';
import { AsyncOptLazy, TraverseState, type ArrayNonEmpty, type AsyncCollectFun, type MaybePromise } from '@rimbu/common';
import { AsyncTransformer, type AsyncFastIterator, type AsyncReducer, type AsyncStream, type AsyncStreamSource } from '@rimbu/stream/async';
import { type AsyncStreamSourceHelpers } from '@rimbu/stream/async-custom';
/**
 * A frozen `IteratorResult` that represents the completed asynchronous iterator state.
 * This value is reused to avoid repeated allocations in async iterator implementations.
 */
export declare const fixedDoneAsyncIteratorResult: Readonly<Promise<IteratorResult<any, any>>>;
/**
 * Returns true if the given `iterator` implements the `AsyncFastIterator` interface.
 * @param iterator - the async iterator instance to test
 */
export declare function isAsyncFastIterator<T>(iterator: AsyncIterator<T>): iterator is AsyncFastIterator<T>;
/**
 * An `AsyncFastIterator` that is already exhausted and never yields values.
 * Its `fastNext` method always resolves to the provided fallback value.
 */
export declare const emptyAsyncFastIterator: AsyncFastIterator<any>;
/**
 * Base class for asynchronous fast iterators that implements `next` in terms of `fastNext`.
 * Subclasses only need to implement the `fastNext` method.
 */
export declare abstract class AsyncFastIteratorBase<T> implements AsyncFastIterator<T> {
    abstract fastNext<O>(otherwise?: AsyncOptLazy<O>): MaybePromise<T | O>;
    return?: () => Promise<any>;
    next(): Promise<IteratorResult<T>>;
}
export declare class AsyncOfIterator<T> extends AsyncFastIteratorBase<T> {
    readonly values: ArrayNonEmpty<AsyncOptLazy<T>>;
    constructor(values: ArrayNonEmpty<AsyncOptLazy<T>>);
    index: number;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): MaybePromise<T | O>;
}
export declare class FromResourceIterator<T, R> extends AsyncFastIteratorBase<T> {
    readonly open: () => MaybePromise<R>;
    readonly createSource: (resource: R) => MaybePromise<AsyncStreamSource<T>>;
    readonly close: ((resource: R) => MaybePromise<void>) | undefined;
    readonly asyncStreamSourceHelpers: AsyncStreamSourceHelpers;
    constructor(open: () => MaybePromise<R>, createSource: (resource: R) => MaybePromise<AsyncStreamSource<T>>, close: ((resource: R) => MaybePromise<void>) | undefined, asyncStreamSourceHelpers: AsyncStreamSourceHelpers);
    resource: R | undefined;
    iterator: AsyncFastIterator<T> | undefined;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncUnfoldIterator<T> extends AsyncFastIteratorBase<T> {
    readonly getNext: (current: T, index: number, stop: Token) => MaybePromise<T | Token>;
    constructor(init: T, getNext: (current: T, index: number, stop: Token) => MaybePromise<T | Token>);
    current: T | Token;
    index: number;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncZipWithIterator<I extends readonly unknown[], R> extends AsyncFastIteratorBase<R> {
    readonly iterables: {
        [K in keyof I]: AsyncStreamSource<I[K]>;
    };
    readonly zipFun: (...values: I) => MaybePromise<R>;
    readonly asyncStreamSourceHelpers: AsyncStreamSourceHelpers;
    constructor(iterables: {
        [K in keyof I]: AsyncStreamSource<I[K]>;
    }, zipFun: (...values: I) => MaybePromise<R>, asyncStreamSourceHelpers: AsyncStreamSourceHelpers);
    readonly sources: AsyncFastIterator<any>[];
    readonly sourcesToClose: Set<AsyncFastIterator<any>>;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<R | O>;
}
export declare class AsyncZipAllWithItererator<I extends readonly unknown[], F, R> extends AsyncFastIteratorBase<R> {
    readonly fillValue: AsyncOptLazy<F>;
    readonly iters: {
        [K in keyof I]: AsyncStreamSource<I[K]>;
    };
    readonly zipFun: (...values: {
        [K in keyof I]: I[K] | F;
    }) => MaybePromise<R>;
    readonly asyncStreamSourceHelpers: AsyncStreamSourceHelpers;
    constructor(fillValue: AsyncOptLazy<F>, iters: {
        [K in keyof I]: AsyncStreamSource<I[K]>;
    }, zipFun: (...values: {
        [K in keyof I]: I[K] | F;
    }) => MaybePromise<R>, asyncStreamSourceHelpers: AsyncStreamSourceHelpers);
    readonly sources: AsyncFastIterator<any>[];
    readonly sourcesToClose: Set<AsyncFastIterator<any>>;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<R | O>;
}
export declare class FromAsyncIterator<T> implements AsyncFastIterator<T> {
    readonly source: AsyncIterator<T>;
    constructor(source: AsyncIterator<T>, close?: () => MaybePromise<void>);
    return?: () => MaybePromise<any>;
    next(): Promise<IteratorResult<T>>;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class FromIterator<T> extends AsyncFastIteratorBase<T> {
    readonly iterator: Iterator<T>;
    constructor(iterator: Iterator<T>, close?: () => MaybePromise<void>);
    return?: () => MaybePromise<any>;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class FromPromise<T> extends AsyncFastIteratorBase<T> {
    readonly promise: () => Promise<AsyncStreamSource<T>>;
    readonly asyncStreamSourceHelpers: AsyncStreamSourceHelpers;
    constructor(promise: () => Promise<AsyncStreamSource<T>>, asyncStreamSourceHelpers: AsyncStreamSourceHelpers, close?: () => MaybePromise<void>);
    iterator: AsyncFastIterator<T> | undefined;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncPrependIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly item: AsyncOptLazy<T>;
    constructor(source: AsyncFastIterator<T>, item: AsyncOptLazy<T>);
    prependDone: boolean;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): MaybePromise<T | O>;
}
export declare class AsyncAppendIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly item: AsyncOptLazy<T>;
    constructor(source: AsyncFastIterator<T>, item: AsyncOptLazy<T>);
    appendDone: boolean;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncIndexedIterator<T> extends AsyncFastIteratorBase<[
    number,
    T
]> {
    readonly source: AsyncFastIterator<T>;
    readonly startIndex: number;
    index: number;
    constructor(source: AsyncFastIterator<T>, startIndex?: number);
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<[number, T] | O>;
}
export declare class AsyncMapIterator<T, T2> extends AsyncFastIteratorBase<T2> {
    readonly source: AsyncFastIterator<T>;
    readonly mapFun: (value: T, index: number) => MaybePromise<T2>;
    constructor(source: AsyncFastIterator<T>, mapFun: (value: T, index: number) => MaybePromise<T2>);
    readonly state: TraverseState;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T2 | O>;
}
export declare class AsyncMapPureIterator<T, A extends readonly unknown[], T2> extends AsyncFastIteratorBase<T2> {
    readonly source: AsyncFastIterator<T>;
    readonly mapFun: (value: T, ...args: A) => MaybePromise<T2>;
    readonly args: A;
    constructor(source: AsyncFastIterator<T>, mapFun: (value: T, ...args: A) => MaybePromise<T2>, args: A);
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T2 | O>;
}
export declare class AsyncConcatIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncStream<T>;
    readonly otherSources: AsyncStreamSource<T>[];
    readonly asyncStreamSourceHelpers: AsyncStreamSourceHelpers;
    iterator: AsyncFastIterator<T>;
    constructor(source: AsyncStream<T>, otherSources: AsyncStreamSource<T>[], asyncStreamSourceHelpers: AsyncStreamSourceHelpers);
    sourceIndex: number;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncFilterIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly pred: (value: T, index: number, halt: () => void) => MaybePromise<boolean>;
    readonly negate: boolean;
    constructor(source: AsyncFastIterator<T>, pred: (value: T, index: number, halt: () => void) => MaybePromise<boolean>, negate: boolean);
    readonly state: TraverseState;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncFilterPureIterator<T, A extends readonly unknown[]> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly pred: (value: T, ...args: A) => MaybePromise<boolean>;
    readonly args: A;
    readonly negate: boolean;
    constructor(source: AsyncFastIterator<T>, pred: (value: T, ...args: A) => MaybePromise<boolean>, args: A, negate: boolean);
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncCollectIterator<T, R> extends AsyncFastIteratorBase<R> {
    readonly source: AsyncFastIterator<T>;
    readonly collectFun: AsyncCollectFun<T, R>;
    constructor(source: AsyncFastIterator<T>, collectFun: AsyncCollectFun<T, R>);
    readonly state: TraverseState;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<R | O>;
}
export declare class AsyncDropWhileIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly pred: (value: T, index: number) => MaybePromise<boolean>;
    readonly negate: boolean;
    constructor(source: AsyncFastIterator<T>, pred: (value: T, index: number) => MaybePromise<boolean>, negate: boolean);
    pass: boolean;
    index: number;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncTakeIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly amount: number;
    constructor(source: AsyncFastIterator<T>, amount: number);
    i: number;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncDropIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncFastIterator<T>;
    readonly amount: number;
    remain: number;
    constructor(source: AsyncFastIterator<T>, amount: number);
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncRepeatIterator<T> extends AsyncFastIteratorBase<T> {
    readonly source: AsyncStream<T>;
    readonly amount?: number | undefined;
    iterator: AsyncFastIterator<T>;
    remain: number | undefined;
    constructor(source: AsyncStream<T>, amount?: number | undefined);
    isEmpty: boolean;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<T | O>;
}
export declare class AsyncReduceIterator<I, R> extends AsyncFastIteratorBase<R> {
    readonly sourceIterator: AsyncFastIterator<I>;
    readonly reducer: AsyncReducer<I, R>;
    constructor(sourceIterator: AsyncFastIterator<I>, reducer: AsyncReducer<I, R>);
    ___instance: AsyncReducer.Instance<I, R> | undefined;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<R | O>;
}
export declare class AsyncTransformerFastIterator<T, R> extends AsyncFastIteratorBase<R> {
    readonly sourceIterator: AsyncFastIterator<T>;
    readonly transformer: AsyncTransformer.Accept<T, R>;
    constructor(sourceIterator: AsyncFastIterator<T>, transformer: AsyncTransformer.Accept<T, R>);
    ___done: boolean;
    ___instance: AsyncReducer.Instance<T, AsyncStreamSource<R>> | undefined;
    ___currentValues: AsyncFastIterator<R> | undefined;
    fastNext<O>(otherwise?: AsyncOptLazy<O>): Promise<R | O>;
}
