/** * This provides the trampoline methods that are shared between synchronous and * asynchronous enhanced generators. Methods dispatch to {@link Sync} or {@link Async} * as appropriate. * * This becomes part of the prototype chain of enhanced generator instances. It does * __not__ modify any global prototypes. * * You should not need to reference this directly. In Typescript, if you need a * type that covers both sync and async enhanced generators, use {@link Enhanced} (for, * generators) or the {@link GeneratorOps} interface (for the functional interface). * * @module Enhancements */ import type { Enhanced, FlatGen, Genable, GeneratorOps, IndexedFn, IndexedPredicate, Reducer, ReturnValue, SyncType } from "./types"; type async = 'async'; /** * Enhancements for generators */ export type { Enhanced } from './types'; /** * The trampoline methods that link enhanced generators to [[Sync]] or [[Async]] * methods. */ export declare abstract class Enhancements { /** * @internal */ abstract _impl: GeneratorOps; /** * @internal */ returning?: any; /** * @internal */ abstract next(...arg: [] | [arg: TNext]): S extends async ? Promise> : IteratorResult; /** * @internal */ abstract return(value: TReturn): S extends async ? Promise> : IteratorReturnResult; /** * @internal */ abstract throw(e: any): S extends async ? Promise> : IteratorReturnResult; /** * @internal */ abstract [Symbol.iterator]: S extends async ? undefined : () => this & IterableIterator; /** * @internal */ abstract [Symbol.asyncIterator]: S extends async ? () => this & AsyncIterableIterator : undefined; /** * @internal */ abstract [Symbol.toStringTag]: S extends async ? 'EnhancedAsyncGenerator' : 'EnhancedGenerator'; /** * Return all of the values from this generator as an array. You do not want to call this on an * infinite generator (for obvious reasons); consider using [[Enhancements.slice|Generator.slice]] or * [[Enhancements.limit|Generator.limit]] to limit the size before calling this. */ asArray(): ReturnValue; /** * Limit the number of values that can be generated. A `RangeError` is thrown if this limit is * exceeded. See [[IEnhacements.slice|Generator.slice]] if you want to truncate. * @param max */ limit(max: number): Enhanced; /** * Operate on each value produced by this generator. f is called with two values, the * value yielded by this generator and a sequential index. * @param f * @param thisArg Value to be supplied as context `this` for function _f_. */ forEach(f: IndexedFn, thisArg?: any): void; /** * Apply the function to each value yielded by this generator. It is called with two arguments, * the value yielded, and a sequential index. The return value is a generator that yields the * values produced by the function. * @param f * @param thisArg Optional value to be supplied as context `this` for function _f_. */ map(f: IndexedFn, thisArg?: any): Enhanced; /** * Return a new enhanced [[Enhancements|Generator]] that yields only the values that satisfy the predicate _f_. * * f receives the value and a sequential index. * @param f * @param thisArg Optional context to be passed as `this` to the predicate. */ filter(f: IndexedPredicate, thisArg?: any): Enhanced; /** * Flatten the values yielded by this generator to level _depth_. Produces a generator that yields * the individual values at each level in depth-first order. Any iterable (including Array) or iterator * will be traversed and its values yielded. * * The return type is currently over-broad * @param depth (default = 1) */ flat(depth?: D): Enhanced, TReturn, TNext>; /** * Flatten the values yielded by applying the function to the values yielded by the generator to level _depth_. * Produces a generator that yields the individual values at each level in depth-first order. Any iterable * (including `Array`) or iterator will be traversed and its values yielded. * * The return type is currently over-broad * @param f * @param depth */ flatMap(f: IndexedFn, S>, depth?: D): Enhanced, TReturn, TNext>; /** * Return a new enhanced [[Enhancements|Generator]] that only yields the indicated values, skipping _start_ initial values * and continuing until the _end_. * @param start * @param end */ slice(start?: number, end?: number): Enhanced; /** * Concatenates generators (or iterators or iterables). * * Ensures that any supplied generators are terminated when this is terminated. * @param gens zero or more additional [[Genable]] to provide values. */ concat(...gens: Genable[]): Enhanced; /** * Like `Array.prototype.reduce`, but the 3rd argument to the reducing function ("array") is omitted * because there is no array. * @param f */ reduce(f: Reducer): ReturnValue; /** * Like `Array.prototype.reduce`, but the 3rd argument to the reducing function ("array") is omitted * because there is no array. * @param f * @param init */ reduce(f: Reducer, init: A): ReturnValue; /** * Returns `true` and terminates the generator if the predicate is true for any of the generator's * yielded values. * * If the generator terminates without having satisfied the predicate, `false` is returned. * @param p predicate to apply to each yielded value. * @param thisArg Optional value to supply as context (`this`) for the predicate */ some(p: IndexedPredicate, thisArg?: any): ReturnValue; /** * Returns `false` and terminates this generator if the predicate is false for any of the generator's * yielded values. * * If the generator terminates without having failed the predicate, `true` is returned. * @param p predicate to apply to each yielded value. * @param thisArg Optional value to supply as context (`this`) for the predicate */ every(p: IndexedPredicate, thisArg?: any): ReturnValue; /** * Returns a new generator that repeats the last value returned by this (or `undefined` if this * did not return any values). * * @param max */ repeatLast(max?: number): Enhanced; /** * Returns a new generator that repeats the supplied value after this generator * completes. * * @param value the value to repeat * @param repetitions The number repetitions; the default is infinite. */ repeat(value: N, repetitions?: number): Enhanced; /** * Combines this generator with additional ones, returning a generator that produces a tuple with * each of their results, with this generator's result first. * * Terminates when any generator terminates. To get other behaviors, use with {@link IEnhancements.repeat | EnhancedGenerator.repeat} * or {@link IEnhancements.repeatLast | EnhancedGenerator.repeatLast}. * @param gens */ zip)[], T, TReturn, TNext>(...gens: G): Enhanced, S, TReturn, TNext>; /** * Trivial, but handy, same as `Array.prototype.join`. * @param sep (default = ','). * * See also {@link EnhancedGenerator.join} */ join(sep?: string): ReturnValue; /** * Sorts the supplied values and returns a sorted array. * @param cmp a comparison function */ sort(cmp?: (a: T, b: T) => number): ReturnValue; } //# sourceMappingURL=enhancements.d.ts.map