Function makeIterable

  • Adds or replaces an iterable implementation that conforms to the Iterable protocol to the target instance, it uses the provided ctx to create an Iterator via createIterator.

    Type Parameters

    • T

      Identifies the target type

    • I

      Identifies the type that will be returned by the iterator

    Parameters

    Returns T & Iterable<I>

    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, so it will just continue
    return false;
    }
    };

    let values: number[] = [];
    let theIterable: Iterable<T> = makeIterable({}, fibCtx);

    iterForOf(theIterable, (value) => {
    values.push(value);
    if (values.length === 10) {
    return -1;
    }
    });

    // Values: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]