Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EnhancedGenerator<T, TReturn, TNext>

Utilities to create and use generators which can be manipulated in various ways.

Most methods come both as instance (prototype) methods and as static methods. They provide equivalent functionality, but the static methods allow use on Iterator and Iterable objects without first converting to a generator.

The [[EnhancedGenerator.enhance]] method will add additional instance methods to an ordinary generator's prototype (a new prototype, not modifying any global prototype!). It can also be used to convert Iterator and Iterable objects to EnhancedGenerator.

For methods which return a EnhancedGenerator, care is take to propagate any Generator.throw and Generator.return calls to any supplied generators, so they can properly terminate.

The exception is EnhancedGenerator.flat (and by extension, EnhancedGenerator.flatMap), which cannot know what nested generators they might encounter in the future. Any generators encountered so far will be terminated, however.

Type parameters

  • T

    the type of values returned in the iteration result.

  • TReturn

    the type of values returned in the iteration result when the generator terminates

  • TNext

    the type of value which can be passed to .next(val).

Hierarchy

  • Enhancements<T, TReturn, TNext, Sync>
    • EnhancedGenerator

Implements

  • Generator<T, TReturn, TNext>
  • Iterable<T>
  • Iterator<T>

Index

Properties

[Symbol.toStringTag]

[Symbol.toStringTag]: "EnhancedGenerator"

Abstract _impl

Optional returning

returning: any

Methods

Abstract [Symbol.iterator]

asArray

  • asArray(): ReturnValue<T[], Sync>

concat

every

  • every(p: IndexedPredicate<T>, thisArg?: any): ReturnValue<boolean, Sync>
  • 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: IndexedPredicate<T>

      predicate to apply to each yielded value.

    • Optional thisArg: any

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

    Returns ReturnValue<boolean, Sync>

filter

flat

  • 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

    • Default value depth: D = 1 as D

      (default = 1)

    Returns Enhanced<Sync, FlatGen<T, D>>

flatMap

  • flatMap<D>(f: IndexedFn<T, FlatGen<T, D>, Sync>, depth?: D): Enhanced<Sync, FlatGen<T, D>>
  • 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

    Parameters

    • f: IndexedFn<T, FlatGen<T, D>, Sync>
    • Default value depth: D = 1 as D

    Returns Enhanced<Sync, FlatGen<T, D>>

forEach

  • forEach(f: IndexedFn<T, void, Sync>, 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: IndexedFn<T, void, Sync>
    • Optional thisArg: any

      Value to be supplied as context this for function f.

    Returns void

join

  • join(sep?: undefined | string): ReturnValue<string, Sync>

limit

map

  • 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: IndexedFn<T, V, Sync>
    • Optional thisArg: any

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

    Returns Enhanced<V, Sync>

Abstract next

  • next(): GenIteratorResult<T, TReturn, Sync>

reduce

repeat

  • repeat<N>(value: N, repetitions?: number): Enhanced<T | N, Sync>
  • Returns a new generator that repeats the supplied value after this generator completes.

    Type parameters

    • N

    Parameters

    • value: N

      the value to repeat

    • Default value repetitions: number = Number.POSITIVE_INFINITY

      The number repetitions; the default is infinite.

    Returns Enhanced<T | N, Sync>

repeatLast

Abstract return

  • return(value: any): GenIteratorResult<T, TReturn, Sync>

slice

some

  • some<T>(p: IndexedPredicate<T, Sync>, thisArg?: any): ReturnValue<boolean, Sync>
  • 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: IndexedPredicate<T, Sync>

      predicate to apply to each yielded value.

    • Optional thisArg: any

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

    Returns ReturnValue<boolean, Sync>

Abstract throw

  • throw(e: any): GenIteratorResult<T, TReturn, Sync>

zip

Generated using TypeDoc