Function getIterator

  • Get a Symbol.iterator from an iterable or a Symbol.asyncIterator from an asynchronous iterable.

    Example

    const iterator = getIterator([1, 2, 3]);
    iterator.next(); // { value: 1, done: false }
    iterator.next(); // { value: 2, done: false }
    iterator.next(); // { value: 3, done: false }
    iterator.next(); // { value: undefined, done: true }

    Type Parameters

    • Iterable extends IsomorphicIterable

    Parameters

    • iterable: Iterable

      Iterable to get the iterator from.

    Returns Iterable extends IsomorphicIterable<Item>
        ? Iterable extends {
                [asyncIterator]() => AsyncIterator<Item, any, undefined>;
            }
            ? {
                next(...args) => Promise<IteratorResult<Item, Item>>;
                return?(value?) => Promise<IteratorResult<Item, Item>>;
                throw?(e?) => Promise<IteratorResult<Item, Item>>;
            }
            : {
                next(...args) => IteratorResult<Item, Item>;
                return?(value?) => IteratorResult<Item, Item>;
                throw?(e?) => IteratorResult<Item, Item>;
            }
        : never

    Iterator instance.