Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EnhancedAsyncGenerator<T, TReturn, TNext>

Type parameters

  • T

  • TReturn

  • TNext

Hierarchy

  • Enhancements<T, TReturn, TNext, async>
    • EnhancedAsyncGenerator

Implements

  • AsyncGenerator<T, TReturn, TNext>
  • AsyncIterable<T>
  • AsyncIterator<T, TReturn, TNext>

Index

Constructors

constructor

  • Type parameters

    • T

    • TReturn

    • TNext

    Returns EnhancedAsyncGenerator<T, TReturn, TNext>

Methods

asArray

  • asArray(): GenPromise<T[]>
  • 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.

    Returns GenPromise<T[]>

concat

  • concat<T, TReturn, TNext>(...gens: (Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "async"> | AsyncGenerator<T, TReturn, TNext> | AsyncIterator<T, TReturn, TNext> | AsyncIterable<T> | Enhancements<T, TReturn, TNext, "sync">)[]): EnhancedAsyncGenerator<T, void | TReturn, TNext>
  • Concatenates generators (or iterators or iterables).

    Ensures that any supplied generators are terminated when this is terminated.

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • Rest ...gens: (Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "async"> | AsyncGenerator<T, TReturn, TNext> | AsyncIterator<T, TReturn, TNext> | AsyncIterable<T> | Enhancements<T, TReturn, TNext, "sync">)[]

      zero or more additional Genable to provide values.

    Returns EnhancedAsyncGenerator<T, void | TReturn, TNext>

every

  • every(p: (v: T, idx: number) => boolean | PromiseLike<boolean>, thisArg?: any): GenPromise<boolean>
  • 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.

    Parameters

    • p: (v: T, idx: number) => boolean | PromiseLike<boolean>

      predicate to apply to each yielded value.

        • (v: T, idx: number): boolean | PromiseLike<boolean>
        • Parameters

          • v: T
          • idx: number

          Returns boolean | PromiseLike<boolean>

    • Optional thisArg: any

      Optional value to supply as context (this) for the predicate

    Returns GenPromise<boolean>

filter

  • filter(f: (v: T, idx: number) => boolean | PromiseLike<boolean>, thisArg?: any): EnhancedAsyncGenerator<T, TReturn, TNext>
  • Return a new enhanced [[Enhancements|Generator]] that yields only the values that satisfy the predicate f.

    f receives the value and a sequential index.

    Parameters

    • f: (v: T, idx: number) => boolean | PromiseLike<boolean>
        • (v: T, idx: number): boolean | PromiseLike<boolean>
        • Parameters

          • v: T
          • idx: number

          Returns boolean | PromiseLike<boolean>

    • Optional thisArg: any

      Optional context to be passed as this to the predicate.

    Returns EnhancedAsyncGenerator<T, TReturn, TNext>

flat

  • flat<D>(depth?: D): any
  • 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

    Type parameters

    • D: number

    Parameters

    • Optional depth: D

      (default = 1)

    Returns any

flatMap

  • flatMap<D>(f: (v: T, idx: number) => any, depth?: D): any
  • 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

    Type parameters

    • D: number = 1

    Parameters

    • f: (v: T, idx: number) => any
        • (v: T, idx: number): any
        • Parameters

          • v: T
          • idx: number

          Returns any

    • Optional depth: D

    Returns any

forEach

  • forEach(f: (v: T, idx: number) => void | PromiseLike<void>, thisArg?: any): void
  • Operate on each value produced by this generator. f is called with two values, the value yielded by this generator and a sequential index.

    Parameters

    • f: (v: T, idx: number) => void | PromiseLike<void>
        • (v: T, idx: number): void | PromiseLike<void>
        • Parameters

          • v: T
          • idx: number

          Returns void | PromiseLike<void>

    • Optional thisArg: any

      Value to be supplied as context this for function f.

    Returns void

join

  • join(sep?: string): GenPromise<string>

limit

  • 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.

    Parameters

    • max: number

    Returns EnhancedAsyncGenerator<T, TReturn, TNext>

map

  • map<V>(f: (v: T, idx: number) => V | PromiseLike<V>, thisArg?: any): EnhancedAsyncGenerator<V, TReturn, TNext>
  • 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.

    Type parameters

    • V

    Parameters

    • f: (v: T, idx: number) => V | PromiseLike<V>
        • (v: T, idx: number): V | PromiseLike<V>
        • Parameters

          • v: T
          • idx: number

          Returns V | PromiseLike<V>

    • Optional thisArg: any

      Optional value to be supplied as context this for function f.

    Returns EnhancedAsyncGenerator<V, TReturn, TNext>

reduce

  • reduce<A, T, TReturn, TNext>(f: (acc: A | T, v: T) => A | PromiseLike<A>): GenPromise<A>
  • reduce<A, T, TReturn, TNext>(f: (acc: A, v: T) => A | PromiseLike<A>, init: A): GenPromise<A>
  • Like Array.prototype.reduce, but the 3rd argument to the reducing function ("array") is omitted because there is no array.

    Type parameters

    • A

    • T

    • TReturn

    • TNext

    Parameters

    • f: (acc: A | T, v: T) => A | PromiseLike<A>
        • (acc: A | T, v: T): A | PromiseLike<A>
        • Parameters

          • acc: A | T
          • v: T

          Returns A | PromiseLike<A>

    Returns GenPromise<A>

  • Like Array.prototype.reduce, but the 3rd argument to the reducing function ("array") is omitted because there is no array.

    Type parameters

    • A

    • T

    • TReturn = T

    • TNext = T

    Parameters

    • f: (acc: A, v: T) => A | PromiseLike<A>
        • (acc: A, v: T): A | PromiseLike<A>
        • Parameters

          • acc: A
          • v: T

          Returns A | PromiseLike<A>

    • init: A

    Returns GenPromise<A>

repeat

  • Returns a new generator that repeats the supplied value after this generator completes.

    Type parameters

    • N

    Parameters

    • value: N

      the value to repeat

    • Optional repetitions: number

      The number repetitions; the default is infinite.

    Returns EnhancedAsyncGenerator<T | N, void, TNext>

repeatLast

slice

  • Return a new enhanced [[Enhancements|Generator]] that only yields the indicated values, skipping start initial values and continuing until the end.

    Parameters

    • Optional start: number
    • Optional end: number

    Returns EnhancedAsyncGenerator<T, undefined | TReturn, TNext>

some

  • some<T>(p: (v: T, idx: number) => boolean | PromiseLike<boolean>, thisArg?: any): GenPromise<boolean>
  • 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.

    Type parameters

    • T

    Parameters

    • p: (v: T, idx: number) => boolean | PromiseLike<boolean>

      predicate to apply to each yielded value.

        • (v: T, idx: number): boolean | PromiseLike<boolean>
        • Parameters

          • v: T
          • idx: number

          Returns boolean | PromiseLike<boolean>

    • Optional thisArg: any

      Optional value to supply as context (this) for the predicate

    Returns GenPromise<boolean>

sort

  • sort(cmp?: (a: T, b: T) => number): GenPromise<T[]>
  • Sorts the supplied values and returns a sorted array.

    Parameters

    • Optional cmp: (a: T, b: T) => number

      a comparison function

        • (a: T, b: T): number
        • Parameters

          • a: T
          • b: T

          Returns number

    Returns GenPromise<T[]>

zip

  • 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 Generator.repeat or Generator.repeatLast.

    Type parameters

    • G: (Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "async"> | AsyncGenerator<T, TReturn, TNext> | AsyncIterator<T, TReturn, TNext> | AsyncIterable<T> | Enhancements<T, TReturn, TNext, "sync">)[]

    • T

    • TReturn

    • TNext

    Parameters

    • Rest ...gens: G

    Returns EnhancedAsyncGenerator<T[], TReturn, TNext>

Generated using TypeDoc