Function createIterableIterator

  • Takes a generator function and returns an iterable iterator or asynchronous iterable iterator object.


    const identityGenerator = function* (value) { yield value; };
    const iterableIterator = createIterableIterator(identityGenerator);

    const fooIdentity = iterableIterator("foo");

    for (const value of fooIdentity) {
    console.log(value); // "foo"

    // Same IterableIterator as above, return values again:

    for (const value of fooIdentity) {
    console.log(value); // "foo"


    Iterable iterator object.

    Type Parameters


    • generatorFunction: GeneratorFunction

      Generator to be used every time [Symbol.iterator] is called.

    Returns GeneratorFunction extends AsynchronousGeneratorFunction<Item> ? GeneratorFunction extends (() => AsyncIterator<Item, any, undefined>) ? AsyncIterableIterator<Item> : IterableIterator<Item> : never