mochi / mochikit

MochiKit makes JavaScript suck less

Home Page:http://mochi.github.io/mochikit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Iter: Incorrect documentation example for Iterator usage

blq opened this issue · comments

from http://trac.mochikit.com/ticket/340

The example code at: http://mochikit.com/doc/html/MochiKit/Iter.html#fn-iter is not correct. The generic usage of iterable shouldn't stop on null values, only on StopIteration.

var it = iter(iterable);
try {
    while (var o = it.next()) { // <-- !
        // use o
    }
} catch (e) {
    if (e != StopIteration) {
        throw e;
    }
    // pass
}

It should rather be:

var it = iter(iterable);
try {
    while (true) { // <-- !
        var o = it.next();
        // use o
    }
} catch (e) {
    if (e != StopIteration) {
        throw e;
    }
    // pass
}

Regards
// Fredrik Blomqvist

Fixed documentation bug for MochiKit.Iter.iter(). Thanks to Fredrik Blomqvist for finding this. Closed by 5ed3ad0.