Function createIterable

  • Create an iterable which conforms to the Iterable protocol, it uses the provided ctx to create an Iterator via createIterator.

    Type Parameters

    • T

      Identifies the type that will be returned by the iterator

    Parameters

    Returns Iterable<T>

    A new Iterable instance

    0.4.2

    let current = 0;
    let next = 1;
    let done = false;
    let fibCtx: CreateIteratorContext<number> = {
    n: function() {
    fibCtx.v = current;
    current = next;
    next = fibCtx.v + next;

    // Return not done
    return false;
    },
    r: function(value) {
    done = true;
    return value;
    }
    };

    let values: number[] = [];
    iterForOf(createIterable(fibCtx), (value) => {
    values.push(value);
    if (values.length === 10) {
    return -1;
    }
    });

    // Done is true
    // done === true
    // Values: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]