Options
All
  • Public
  • Public/Protected
  • All
Menu

Load the full system with a single import.

preferred

Index

Type aliases

GenType

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

Returns the element type of a Genable

typeparam T

the value type produced by the Genable

Type parameters

GenUnion

GenUnion<Arr>: Arr extends [] ? Arr : Arr extends infer E[] ? E extends Genable<infer E2, infer S, infer EReturn, infer ENext> ? 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, TReturn, TNext>: { async: AsyncGenerator<T, TReturn, TNext> | AsyncIterator<T, TReturn, TNext> | AsyncIterable<T> | Enhancements<T, TReturn, TNext, S> | Genable<T, Sync, TReturn, TNext>; sync: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, S> }[S]

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

Type parameters

IteratorType

IteratorType<I>: I extends Iterator<infer T> ? T : I extends AsyncIterator<infer T> ? T : I extends Iterable<infer T> ? T : I extends AsyncIterable<infer T> ? T : never

Extract the value type being iterated over. I can be an iterator type or an iterable type, synchronous or asynchronous.

typeparam A

type describing an iteration.

Type parameters

  • I

KeyFn

KeyFn: (k: any) => any

Type declaration

    • (k: any): any
    • Parameters

      • k: any

      Returns any

QueueFactory

QueueFactory<T>: () => Queue<T>

Type parameters

  • T

Type declaration

    • A factory function that returns a Queue. It will be called with no arguments.

      Returns Queue<T>

Reducer

Reducer<A, T, Init, S>: { async: any; sync: any }[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: A | T

    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.

SyncType

SyncType: Sync | Async

Selector type to select the types for synchronous or asynchronous generators. Reference the members as Sync.type or Async.type

Functions

Const delay

  • delay(ms: number, value?: any): Promise<unknown>
  • Delay for the specified number of milliseconds.

    Parameters

    • ms: number
    • Optional value: any

    Returns Promise<unknown>

Const doCatch

  • doCatch<A, R>(f: (...args: A) => R, onError?: (e: Error) => R): (...args: A) => undefined | R
  • Wrap a function in a catch block.

    Type parameters

    • A: any[]

    • R

    Parameters

    • f: (...args: A) => R
        • (...args: A): R
        • Parameters

          • Rest ...args: A

          Returns R

    • Optional onError: (e: Error) => R

      Called when an error is thrown. The return value is returned. If not supplied, undefined is returned.

        • (e: Error): R
        • Parameters

          • e: Error

          Returns R

    Returns (...args: A) => undefined | R

      • (...args: A): undefined | R
      • Parameters

        • Rest ...args: A

        Returns undefined | R

Const eventToGenerator

  • eventToGenerator<T, R>(queue?: QueueFactory<T | EndMsg<R>>): [AsyncGenerator<T, R, unknown>, Controller<T, any>]
  • async generator function eventToGenerator(queue) returns [generator, controller]

    Create a generator that can be made to return values to be supplied by a callback.

    • queue: A QueueFactory function that returns the Queue to use.
    • generator: The generator being controlled.
    • controller: A Controller object with the following:
      • send(value): send the next value to generate.
      • end(): Cause the generator to end
      • throw(error): Cause the generator to throw an exception.
      • clear(): Remove any pending queue items.

    end and throw are synchronous with the queue. That is, they cause the queue to end or throw when the consumer of the generator has read everything prior in the queue.

    queue should return a Queue object that implements .length, .push(), .shift(), and .clear(). The default implementation is Denque, which is fast for unbounded size.

    The returned generator may be enhanced with {@link Async_.enhance|Async.enhance} if desired.

    Other QueueFactory functions provided:

    • queue1: returns a "queue" of maximum length 1. Older entries are discarded.
    • queueSticky`: Returns a queue that returns the last value seen, forever (or until cleared).
    • queueOldest(n): Call with n to set the size; when full new values are discarded.
    • queueNewest(n): Call with n to set the size; when full old values are discarded.
    • queueUnique: Returns a queue that discards duplicate enqueued values.

    Type parameters

    • T

    • R = void

    Parameters

    Returns [AsyncGenerator<T, R, unknown>, Controller<T, any>]

Const isAsyncGenable

  • isAsyncGenable<T, TReturn, TNext>(g: any): g is AsyncIterator<T, TReturn, TNext> | AsyncIterable<T> | AsyncGenerator<T, TReturn, TNext> | Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "async"> | Enhancements<T, TReturn, TNext, "sync">
  • Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • g: any

    Returns g is AsyncIterator<T, TReturn, TNext> | AsyncIterable<T> | AsyncGenerator<T, TReturn, TNext> | Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "async"> | Enhancements<T, TReturn, TNext, "sync">

Const isAsyncGenerator

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

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • g: any

    Returns g is AsyncGenerator<T, any, unknown>

Const isAsyncIterable

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

    Type parameters

    • K

    • KReturn = K

    • KNext = K

    Parameters

    • i: any

    Returns i is AsyncIterable<K> & { [asyncIterator]: any }

Const isAsyncIterableIterator

  • isAsyncIterableIterator<K, KReturn, KNext>(i: any): i is AsyncIterable<K> & { [asyncIterator]: any }
  • 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

    • KReturn = K

    • KNext = K

    Parameters

    • i: any

    Returns i is AsyncIterable<K> & { [asyncIterator]: any }

Const isAsyncIterator

  • isAsyncIterator<K, KReturn, KNext>(i: any): i is AsyncIterator<K, KReturn, KNext>
  • 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

    • KReturn = K

    • KNext = K

    Parameters

    • i: any

    Returns i is AsyncIterator<K, KReturn, KNext>

Const isGenable

  • isGenable<T, TReturn, TNext>(g: any): g is Iterator<T, TReturn, TNext> | Iterable<T> | Generator<T, TReturn, TNext> | Enhancements<T, TReturn, TNext, "sync">
  • 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

    • TReturn = T

    • TNext = T

    Parameters

    • g: any

    Returns g is Iterator<T, TReturn, TNext> | Iterable<T> | Generator<T, TReturn, TNext> | Enhancements<T, TReturn, TNext, "sync">

Const isGenerator

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

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • g: any

    Returns g is Generator<T, TReturn, TNext>

Const isIterable

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

    Type parameters

    • K

    • KReturn = K

    • KNext = K

    Parameters

    • i: any

    Returns i is Iterable<K> & { [iterator]: any }

Const isIterableIterator

  • isIterableIterator<K, KReturn, KNext>(i: any): i is IterableIterator<K> & { [iterator]: any }
  • 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

    • KReturn = K

    • KNext = K

    Parameters

    • i: any

    Returns i is IterableIterator<K> & { [iterator]: any }

Const isIterator

  • isIterator<K, KReturn, KNext>(i: any): i is Iterator<K, KReturn, KNext>
  • 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

    • KReturn = K

    • KNext = K

    Parameters

    • i: any

    Returns i is Iterator<K, KReturn, KNext>

Const queue1

  • A QueueFactory that returns a Queue of maximum length 1, which discards older values.

    Type parameters

    • V

    Returns Queue<V>

Const queueNewest

  • Make a QueueFactory that returns a Queue of maximum length n, which discards older values.

    Type parameters

    • V

    Parameters

    • Optional n: number

      the number of entries, default = 1.

    Returns QueueFactory<V>

Const queueOldest

  • Make a QueueFactory that returns a Queue of maximum length n, which discards newer values.

    Type parameters

    • V

    Parameters

    • Optional n: number

      the number of entries, default = 1.

    Returns QueueFactory<V>

Const queueSticky

  • queueSticky<V>(): Queue<V>
  • A QueueFactory that returns a Queue of maximum length 1, which discards older values, but returns the last seen forever (until cleared).

    Type parameters

    • V

    Returns Queue<V>

Const queueUnique

  • function queueUnique({newest, keyFn}): () =>

    Return a QueueFactory, which supplies Queue instances that discard already-enqueued entries. Values can be re-enqueued once delivered.

    • newest: if false (the default), values are dequeued in the order they were first enqueued. Using {newest: true} deprioritizes more active values so less-busy items can get through. But in a sustained-busy situation, there is no guarantee they will ever be delivered. This can be an advantage or disadvantage, depending on requirements.
    • keyFn: A function to identify what values count as "equal". The default regards +0 and -0 as the same, NaN's as all the same, and otherwise behaves as ===.

    Type parameters

    • E

    Parameters

    Returns QueueFactory<E>

Const queueUpdateShallow

  • queueUpdateShallow<E>(init?: Partial<E>): () => Queue<Partial<E>>
  • Accepts objects, and returns just the fields that have changed (are no longer ===).

    This does not distinguish between deleted keys and keys assigned a value of undefined in the input. In the output, a deleted key is represented as present with a value of undefined.

    Type parameters

    • E: object

    Parameters

    • Optional init: Partial<E>

      The initial value

    Returns () => Queue<Partial<E>>

Const range

  • range(start?: number, end?: number, step?: number): G.Sync.Generator<number, void, void>
  • Produce numbers from start to end incremented by step. Step may be positive or negative, but not zero.

    Produces an EnhancedGenerator.

    Parameters

    • Optional start: number

      (default = 0)

    • Optional end: number

      (default = Number.MAX_SAFE_INTEGER)

    • Optional step: number

      (default = 1)

    Returns G.Sync.Generator<number, void, void>

toAsyncGenerator

  • toAsyncGenerator<T, TReturn, TNext>(i: 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">): AsyncGenerator<T, TReturn, TNext>
  • 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. This generator is not enhanced. Use Async.enhance on the result if you need an enhanced generator.

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • i: 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">

    Returns AsyncGenerator<T, TReturn, TNext>

toAsyncIterable

  • toAsyncIterable<T, TReturn, TNext>(i: 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">): FullIterable<T, Async, TReturn, TNext>
  • 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

    • TReturn

    • TNext

    Parameters

    • i: 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">

    Returns FullIterable<T, Async, TReturn, TNext>

toAsyncIterableIterator

  • toAsyncIterableIterator<T, TReturn, TNext>(i: 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">): FullIterableIterator<T, Async, TReturn, TNext>
  • Similar to toAsyncGenerator, but does not require the presence of AsyncGenerator.return or AsyncGenerator.throw methods.

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • i: 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">

    Returns FullIterableIterator<T, Async, TReturn, TNext>

toAsyncIterator

  • toAsyncIterator<T, TReturn, TNext>(i: 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">): AsyncIterator<T, TReturn, TNext>
  • 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

    • TReturn

    • TNext = T

    Parameters

    • i: 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">

    Returns AsyncIterator<T, TReturn, TNext>

toGenerator

  • toGenerator<T, TReturn, TNext>(i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">): Generator<T, TReturn, TNext>
  • 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. This generator is not enhanced. Use Sync.enhance on the result if you need an enhanced generator.

    Type parameters

    • T

    • TReturn = T

    • TNext = T

    Parameters

    • i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">

    Returns Generator<T, TReturn, TNext>

toIterable

  • toIterable<T, TReturn, TNext>(i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">): FullIterable<T, Sync, TReturn, TNext>
  • 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

    • TReturn = T

    • TNext = T

    Parameters

    • i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">

    Returns FullIterable<T, Sync, TReturn, TNext>

toIterableIterator

  • toIterableIterator<T, TReturn, TNext>(i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">): FullIterableIterator<T, Sync, TReturn, TNext>
  • Similar to toGenerator, but does not require the presence of Generator.return or Generator.throw methods.

    Type parameters

    • T

    • TReturn = T

    • TNext = T

    Parameters

    • i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">

    Returns FullIterableIterator<T, Sync, TReturn, TNext>

toIterator

  • toIterator<T, TReturn, TNext>(i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">): Iterator<T, TReturn, TNext>
  • 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

    • TReturn

    • TNext

    Parameters

    • i: Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">

    Returns Iterator<T, TReturn, TNext>

Generated using TypeDoc