Andy Wingo (2013-07-23T08:33:57.000Z)
Hello,

On Wed 17 Jul 2013 10:50, "Claus Reinke" <claus.reinke at talk21.com> writes:

>>>    // this doesn't work
>>>    function* generator(){
>>>        [1,2,3].forEach( function(x){ yield x } )
>>>    }
>
>>> For the specific case of forEach et al
>> What do you mean by "et al"? I don't believe .map, .reduce or .filter
>> are any interesting to use alongside generators.
>
> And why not? Because yield is a statement

Yield is an expression.

> Why shouldn't I be able to traverse an array, using the ES5 standard
> operations for doing so, yielding intermediate results from the
> traversal (recall also that yield can return data sent in via .next,
> for incorporation into such traversals)?

You certainly can, with one modification: using *ES6* standard
operations (external iterators vs the ES5 forEach internal iterator).
Generators and non-generator iterators and for-of and comprehensions
hang together really nicely in practice.

>>     function* g(){
>>         for(x of [1,2,3]) yield transform(x);
>>     }
>
> Methods can be replaced by built-ins. It is the reverse that
> is now broken.

Au contraire, but it requires a re-think on your part: favor external
iterators over internal iterators.

Andy
domenic at domenicdenicola.com (2013-07-23T16:51:28.670Z)
On Wed 17 Jul 2013 10:50, "Claus Reinke" <claus.reinke at talk21.com> writes:
> And why not? Because `yield` is a statement

`yield` is an expression.

> Why shouldn't I be able to traverse an array, using the ES5 standard
> operations for doing so, yielding intermediate results from the
> traversal (recall also that yield can return data sent in via .next,
> for incorporation into such traversals)?

You certainly can, with one modification: using *ES6* standard
operations (external iterators vs the ES5 forEach internal iterator).
Generators and non-generator iterators and for-of and comprehensions
hang together really nicely in practice.

> Methods can be replaced by built-ins. It is the reverse that
> is now broken.

Au contraire, but it requires a re-think on your part: favor external
iterators over internal iterators.