Options
All
  • Public
  • Public/Protected
  • All
Menu

Module asyncIter

Callable

  • Returns an AsyncIter yielding items from a list of iterables

    Type parameters

    • E

      The type of elements the Iterable yields.

    Parameters

    • iterable: AnyIterable<E>

      the source iterable

    • Rest ...iterables: AnyIterable<E>[]

      other iterables to concatenate

    Returns AsyncIter<E>

Index

Variables

Const collector

collector: Op = Op

Const ops

ops: ops = opsCollectors

Functions

empty

flatten

  • Returns an AsyncIter that yields the values from each Iterable in the given Iterable.

    example
    asyncIter.flatten(iter.of(iter.of(1, 3)), iter.of(Iter.of (2, 4)).toAsync())
    result: (1, 3, 2, 4)

    Type parameters

    • E

      the element type that the iterables of the given iterable yield.

    Parameters

    • iterable: AsyncIterable<AnyIterable<E>>

      the source async iterable of iterables

    Returns AsyncIter<E>

fromIterator

  • fromIterator<E>(createIterator: function): AsyncIter<E>
  • Returns an AsyncIter yielding items from an iterator

    Type parameters

    • E

      The type of elements the Iterator yields.

    Parameters

    Returns AsyncIter<E>

fromLazy

  • fromLazy<E>(create: function): AsyncIter<E>
  • Returns an AsyncIter yielding a single element the is created lazily when the item is requested.

    typeparm

    E the type of the element that is created

    example
    asyncIter.fromLazy(Math.random)
    result: (0.243442)

    Type parameters

    • E

    Parameters

    • create: function

      A function that creates a promise that resolves to the element to yield

        • (): Promise<E>
        • Returns Promise<E>

    Returns AsyncIter<E>

fromPromise

  • fromPromise<E>(promise: Promise<E>): AsyncIter<E>
  • Returns an AsyncIter that yields the result of the given promise once it has resolve.

    example

    `typescript asyncIter.fromPromise(new Promise(resolve => setTimeout(() => resolve('test'), 1000))).forEach(v => console.log(v)) result: test

    Type parameters

    • E

      the type of the promise value

    Parameters

    • promise: Promise<E>

      the promise that returns a value

    Returns AsyncIter<E>

fromSingleCallback

  • fromSingleCallback<E>(consume: function): AsyncIter<E>
  • Returns an AsyncIter that yields the first value that the given callback consumer passes to the callback.

    Type parameters

    • E: any[]

      the type of the array of arguments that are passed to the callback

    Parameters

    • consume: function

      a function that takes a callback function

        • (emit: function): void
        • Parameters

          • emit: function
              • (...v: E): void
              • Parameters

                • Rest ...v: E

                Returns void

          Returns void

    Returns AsyncIter<E>

generate

  • generate<E>(init: Promise<E>, next: function): AsyncIter<E>
  • Returns an AsyncIter yielding a potentially infinite sequence of elements using a generation function

    example
    asyncIter.generate(2, v => v * v)
    result: (2, 4, 16, 256, ...)

    Type parameters

    • E

      The type of elements the Iter yields.

    Parameters

    • init: Promise<E>

      A promise resolving to the initial value to yield.

    • next: function

      Function the returns a promise resolving to the next value to yield based on the current value.

        • (current: E, index: number): Promise<E | undefined>
        • Parameters

          • current: E
          • index: number

          Returns Promise<E | undefined>

    Returns AsyncIter<E>

unfold

  • unfold<S, E>(init: Promise<S>, next: function): AsyncIter<E>
  • Returns an AsyncIter yielding a potentially infinite sequence of elements using an unfolding function

    example
    asyncIter.unfold(1, s => ['a'.repeat(s), s * 2])
    result: ('a', 'aa', 'aaaa', 'aaaaaaaa', ...)

    Type parameters

    • S

      the internal 'state' of the unfolding function

    • E

      the type of elements the Iter yields.

    Parameters

    • init: Promise<S>

      The initial internal 'state' of the unfolding function

    • next: function

      A function taking the current state, and returning an optional tuple with the element to yield and the next state.

        • (currentState: S, index: number): Promise<[E, S] | undefined>
        • Parameters

          • currentState: S
          • index: number

          Returns Promise<[E, S] | undefined>

    Returns AsyncIter<E>

Generated using TypeDoc