Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Generators

An extension to generators, that provides for operations like:

  • map<T, R>(gen: Generator) => (fn: T => R) => Generator
  • EnhancedGenerator.map(fn: T => R) => Generator

Index

Type aliases

GenType

GenType<G>: G extends Genable<infer T> ? T : never

Returns the element type of a Genable

typeparam

the value type produced by the Genable

Type parameters

  • G

GenUnion

GenUnion<Arr>: Arr extends [] ? Arr : Arr extends Array<infer E> ? E extends Genable<infer E2> ? E2 : never : never

Returns the union of the element types of a tuple of generators.

Type parameters

  • Arr

    a tuple type of Genable's.

Genable

Genable<T>: Generator<T> | Iterator<T> | Iterable<T>

Any Generator, Iterator, or Iterable, which can be coerced to a EnhancedGenerator.

Type parameters

  • T

    the value type produced by the Genable

Reducer

Reducer<A, T, Init>: (acc: Init | A, v: T) => A

A function which can be supplied to a reduce method.

For the case where an init value of type A will be supplied, use:

For the case where no init value will be supplied, use:

For cases where an init value may or may not be supplied:

For cases where A = T (for example, reducing a set of numbers to a number):

Type parameters

  • A

    The accumulated result.

  • T

    The individual element values supplied to be reduced.

  • Init

    the initial value for the reducer. If no init value is supplied, the first call will be T; otherwise it will be A.

Type declaration

    • (acc: Init | A, v: T): A
    • Parameters

      • acc: Init | A
      • v: T

      Returns A

Functions

Const isGenable

  • isGenable<T>(g: Iterator<T> | Iterable<T> | Generator<T> | any): g is Genable<T>
  • Predicate/type guard to determine if an object is Genable. An object is Genable if it supports the Iterator or Iterable protocols. (Generators support both).

    Type parameters

    • T

    Parameters

    • g: Iterator<T> | Iterable<T> | Generator<T> | any

    Returns g is Genable<T>

Const isGenerator

  • isGenerator(g: any): g is Generator
  • Predicate/type guard to determine if an object is (or looks like, structurally) a Generator.

    Parameters

    • g: any

    Returns g is Generator

Const isIterable

  • isIterable<K>(i: Iterable<K> | any): i is Iterable<K>
  • Predicate/type guard, returns true if the argument satisfies the Iterable protocol (has a [Symbol.iterator] method).

    Type parameters

    • K

    Parameters

    • i: Iterable<K> | any

    Returns i is Iterable<K>

Const isIterableIterator

  • isIterableIterator<K>(i: Iterable<K> | Iterator<K> | any): i is IterableIterator<K>
  • Predicate/type guard, returns true if the argument satisfies the Iterable protocol (has a [Symbol.iterator] method) and the Iterator protocol (a next() method).

    Type parameters

    • K

    Parameters

    • i: Iterable<K> | Iterator<K> | any

    Returns i is IterableIterator<K>

Const isIterator

  • isIterator<K>(i: Iterable<K> | any): i is Iterator<K>
  • Predicate/type guard, returns true if the argument satisfies the Iterator protocol (has a next() method).

    Type parameters

    • K

    Parameters

    • i: Iterable<K> | any

    Returns i is Iterator<K>

Const range

  • Parameters

    • Default value start: number = 0

      (default = 0)

    • Default value end: number = Number.MAX_SAFE_INTEGER

      (default = Number.MAX_SAFE_INTEGER)

    • Default value step: number = 1

      (default = 1)

    Returns EnhancedGenerator<number>

toGenerator

  • toGenerator<T>(i: Genable<T>): Generator<T>
  • Coerce an object to an object that can act as a generator (that is, satisfy both Iterator and Iterable).

    If it is an Iterator but not Iterable, or Iterable but not Iterator, it is wrapped in a generator.

    Type parameters

    • T

    Parameters

    Returns Generator<T>

toIterable

  • toIterable<T>(i: Genable<T>): Iterable<T>
  • Coerce a Genable object to Iterable. If it is already an Iterable, it is returned unchanged. If it is an Iterator, it is wrapped in an object with a [Symbol.iterator] method that returns the supplied iterator.

    Type parameters

    • T

    Parameters

    Returns Iterable<T>

toIterableIterator

  • toIterableIterator<T>(i: Genable<T>): IterableIterator<T>
  • Similar to toGenerator, but does not require the presence of Generator.return or Generator.throw methods.

    Type parameters

    • T

    Parameters

    Returns IterableIterator<T>

toIterator

  • toIterator<T>(i: Genable<T>): Iterator<T>
  • Coerce a Genable object to an Iterator. If the object is a Generator or an Iterator it is returned, while if it is an Iterable, [Symbol.iterator]() is invoked.

    Type parameters

    • T

    Parameters

    Returns Iterator<T>

Generated using TypeDoc