What are iterFunc and iterGen?

The * means to exhaust the yield operand's value, otherwise you're just yielding that value. PEP-380 is the basis:

"The following new expression syntax will be allowed in the body of a generator:

yield from<expr>

where <expr> is an expression evaluating to an iterable, from which an iterator is extracted. The iterator is run to exhaustion, during which time it yields and receives values directly to or from the caller of the generator containing the yield from expression (the "delegating generator")."


There's no point requiring an iterator not an iterable given the special form. Are you actually concerned about the * being too little syntax for the special form's semantics?

/be

Axel Rauschmayer wrote:
I don’t like the implicit iteration of the operand that happens for yield* 
this.left. To me, superficially, it looks like this.left is yielded. Instead, 
it is more a self-recursive call. Compare:

     function visit(visitor) {
         if (this.left) {
             iterFunc(this.left, visitor);
         }
         visitor(this.label);
         if (this.right) {
             iterFunc(this.right, visitor);
         }
     }

     function* iterate() {
         if (this.left) {
             yield* iterGen(this.left);
         }
         yield this.label;
         if (this.right) {
             yield* iterGen(this.right);
         }
     }

     Tree.prototype.visit = visit;
     Tree.prototype[iterator] = iterate;
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to