Given that redundant calls to `return()` don’t make a difference (h/t Bergi),
wouldn’t the iteration protocol be simpler if iterators were always closed
(versus only if iteration finishes abruptly). The code of generators wouldn’t
change (`finally` etc.), but “manually implemented” iterators could be written
without the check in line (A). They’d become simpler and more similar to
generators and `finally`.
```js
let iterable = {
[Symbol.iterator]() {
return {
next() {
if (iterationIsDone()) {
return { done: true };
} else {
let result = { value: nextValue(), done: false };
if (iterationIsDone()) { // (A)
cleanUp();
}
return result;
}
},
return(value) {
if (! iterationIsDone()) {
cleanUp();
}
return { value: value, done: true };
}
}
}
}
```
--
Dr. Axel Rauschmayer
[email protected]
rauschma.de
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss