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

Async

Async: "async"

Sync/Async type selector

AsyncGenable

AsyncGenable<T>: Genable<T, Async>

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

Type parameters

  • T

    the value type produced by the Genable

Enhanced

Enhanced<T, S, TReturn, TNext>: { async: EnhancedAsyncGenerator<T, TReturn, TNext>; sync: EnhancedGenerator<T, TReturn, TNext> }[S]

An enhanced Generator

Type parameters

  • T

    The value type yielded by the Generator.

  • S: SyncType

    Selects for Sync or Async operation.

  • TReturn

  • TNext

GenType

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

Returns the element type of a Genable

typeparam

the value type produced by the Genable

Type parameters

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, S>: { async: AsyncGenerator<T> | AsyncIterator<T> | AsyncIterable<T> | Enhancements<T, any, unknown, S> | Genable<T, Sync>; sync: Generator<T> | Iterator<T> | Iterable<T> | Enhancements<T, any, unknown, S> }[S]

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

Type parameters

Reducer

Reducer<A, T, Init, S>: { async: (acc: Init | A, v: T) => A | PromiseLike<A>; sync: (acc: Init | A, v: T) => A }[S]

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.

  • S: SyncType

    either Sync or Async.

Sync

Sync: "sync"

Sync/Async type selector

SyncType

SyncType: Sync | Async

Sync/Async type selector

Variables

Const Async

Async: Async_ = new Async_()

Const Sync

Sync: Sync_ = new Sync_()

Functions

Const isAsyncGenable

  • isAsyncGenable<T>(g: AsyncIterator<T> | AsyncIterable<T> | AsyncGenerator<T> | any): g is Genable<T, Async>
  • Type parameters

    • T

    Parameters

    • g: AsyncIterator<T> | AsyncIterable<T> | AsyncGenerator<T> | any

    Returns g is Genable<T, Async>

Const isAsyncGenerator

  • isAsyncGenerator<T>(g: Genable<T, Async> | any): g is AsyncGenerator<T>
  • Predicate/type guard to determine if an object is (or looks like, structurally) a AsyncGenerator.

    Type parameters

    • T

    Parameters

    Returns g is AsyncGenerator<T>

Const isAsyncIterable

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

    Type parameters

    • K

    Parameters

    • i: AsyncIterable<K> | any

    Returns i is AsyncIterable<K>

Const isAsyncIterableIterator

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

    Type parameters

    • K

    Parameters

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

    Returns i is IterableIterator<K>

Const isAsyncIterator

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

    Note: There is no way to statically distinguish between an Iterator and an AsyncIterator. You will get runtime errors if you don't anticipate the distinction.

    Type parameters

    • K

    Parameters

    • i: AsyncIterable<K> | any

    Returns i is AsyncIterator<K>

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<T>(g: Genable<T> | any): g is Generator<T>
  • Predicate/type guard to determine if an object is (or looks like, structurally) a Generator.

    Type parameters

    • T

    Parameters

    Returns g is Generator<T>

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

    Note: There is no way to statically distinguish between an Iterator and an AsyncIterator. You will get runtime errors if you don't anticipate the distinction.

    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>

toAsyncGenerator

  • Coerce an object to an object that can act as a async generator (that is, satisfy both Iterator and Iterable).

    If it is an AsyncIterator but not AsyncIterable, or AsyncIterable but not AsyncIterator, it is wrapped in an async generator.

    Type parameters

    • T

    Parameters

    Returns AsyncGenerator<T>

toAsyncIterable

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

    Type parameters

    • T

    Parameters

    Returns AsyncIterable<T>

toAsyncIterableIterator

  • toAsyncIterableIterator<T>(i: Genable<T, Async>): AsyncIterableIterator<T>

toAsyncIterator

  • toAsyncIterator<T>(i: Genable<T, Async>): AsyncIterator<T>
  • Coerce an async Genable object to an AsyncIterator. 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 AsyncIterator<T>

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, Sync>): IterableIterator<T>

toIterator

  • toIterator<T>(i: Genable<T>): Iterator<T>
  • Coerce a sync 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