import { IEnumerator } from '../enumerator'; import type { IEnumerable } from '../enumerable'; /** * A symbol, indicating to the state machine * that the sequence has no more elements. */ export declare const DONE: unique symbol; export declare type Next = typeof DONE | T; declare type EnumeratorStateMachineSetup = () => EnumeratorStateMachineNextGenerator; declare type EnumeratorStateMachineNextGenerator = () => T | typeof DONE; export declare const enum EnumeratorState { /** * The state machine will be set to this state, if the * sequence has no more elements. */ Stop = -1, /** * Sets up variables like the enumerator for iteration. * This happens, when moveNext is called while the state is Setup. * The State will then be set to Stop. */ Setup = 0, /** * Is set after the `next` call to get the next * element of the sequence. If `next` returns DONE, the state * will be kept as `Stop`. */ HasNextElement = 1 } /** * An alternative implementation to the JavaScript * generator function that uses a bit more memory * but is significantly faster. */ export declare abstract class EnumeratorStateMachine> implements IEnumerator { current?: TEnumerator; protected state: EnumeratorState; /** * Creates a new instance of a state machine * using the setup function to create the next generator. */ static create(setup: EnumeratorStateMachineSetup): EnumeratorStateMachine; /** * Resets the internal state to be `Setup`. */ reset(): void; moveNext(): boolean; /** * Returns the next value, the enumerator * should return or DONE if the sequence * has no more elements. */ abstract next(): Next; /** * Sets up the state machine; * this is called the first time moveNext * is called or after the state machine is reset. */ abstract setup(): void; getEnumerator(): IEnumerator; [Symbol.iterator](): Iterator; } export interface EnumeratorStateMachine> extends IEnumerable { } export {};