Function toIterable

  • Converts a synchronous Iterator into a synchronous Iterable, so it can be used as a pipeline source/input.

    Note that an iterator type can only be determined by starting the iteration, which is what this method does. So if getting the first iterator value throws an error, it will occur outside the pipeline.

    Passing it an already iterable object will just reuse it.

    Type Parameters

    • T

    Parameters

    • i: Iterator<T, any, undefined>

    Returns Iterable<T>

  • Converts an asynchronous AsyncIterator into asynchronous AsyncIterable, so it can be used as a pipeline source/input.

    Note that an iterator type can only be determined by starting the iteration, which is what this method does. So if getting the first iterator value throws an error, it will occur outside the pipeline.

    Passing it an already iterable object will just reuse it.

    Type Parameters

    • T

    Parameters

    • i: AsyncIterator<T, any, undefined>

    Returns AsyncIterable<T>

  • Converts an array-like object into a synchronous Iterable, so it can be used as a pipeline source/input.

    Type Parameters

    • T

    Parameters

    • i: ArrayLike<T>

    Returns Iterable<T>

  • Converts a Promise into a one-value AsyncIterable, so it can be used as a pipeline source/input.

    import {pipe, toIterable, spread} from 'iter-ops';

    const input = Promise.resolve([1, 2, 3, 4, 5]);

    const i = pipe(
    toIterable(input),
    spread()
    ); // = AsyncIterableExt<number>

    for await(const a of i) {
    console.log(a); // 1, 2, 3, 4, 5
    }

    Type Parameters

    • T

    Parameters

    • i: Promise<T>

    Returns AsyncIterable<T>

  • Converts a simple value into a one-value synchronous iterable, so it can be used as a pipeline source/input.

    Type Parameters

    • T

    Parameters

    • i: T

    Returns Iterable<T>