Function iteratorToIterable

  • Category

    Returns an iterable that uses a provided iterator.

    Time complexity: O(1)

    Space complexity: O(1)

    Type Parameters

    • T

    Parameters

    • iterator: Iterator<T, any, undefined>

      The iterator to convert to an iterable

    Returns Iterable<T>

    An iterable that uses iterator

    Iterable

    const iterable = [1, 2, 3];
    const iterator = iterable[Symbol.iterator]();

    iteratorToIterable(iterator); // { [Symbol.iterator]: () => iterator }