Hello,
On Wed 17 Jul 2013 10:50, "Claus Reinke" <[email protected]> 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
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss