Re: How would we copy an iterator?

2015-02-23 Thread Salvador de la Puente González
El 23/02/2015 20:29, Brendan Eich bren...@mozilla.org escribió: Benjamin (Inglor) Gruenbaum wrote: Of course this example is contrived! It's the simplest example I could think of. I do think it stands for every example of any iterator that takes any input from `.send` or `.throw`. I have

Re: How would we copy an iterator?

2015-02-23 Thread Benjamin (Inglor) Gruenbaum
Why not? The generator would switch on sent value, in a loop. Well, let's say we have an iterator that does nothing once, returns what was sent to it the first 5 times and then is done: ```js function* gen(){ var res = yield; for(var i = 0; i 5; i++){ res = yield res; } } var iter =

Re: How would we copy an iterator?

2015-02-23 Thread Brendan Eich
Benjamin (Inglor) Gruenbaum wrote: Of course this example is contrived! It's the simplest example I could think of. I do think it stands for every example of any iterator that takes any input from `.send` or `.throw`. I have plenty of other contrived examples (implementing `fork` like this by

Re: How would we copy an iterator?

2015-02-23 Thread Benjamin (Inglor) Gruenbaum
Of course this example is contrived! It's the simplest example I could think of. I do think it stands for every example of any iterator that takes any input from `.send` or `.throw`. I have plenty of other contrived examples (implementing `fork` like this by using generators for coroutines with

Re: How would we copy an iterator?

2015-02-23 Thread Brendan Eich
Salvador de la Puente González wrote: Yep. This was already discussed in the topic I mentioned before. Just to remember, the real problem with tee() is that the generators are not actually independent as you can not .send() different information to each one to make them diverge. Why not?

Re: How would we copy an iterator?

2015-02-23 Thread Tab Atkins Jr.
On Mon, Feb 23, 2015 at 10:34 AM, Brendan Eich bren...@mozilla.org wrote: Salvador de la Puente González wrote: Yep. This was already discussed in the topic I mentioned before. Just to remember, the real problem with tee() is that the generators are not actually independent as you can not

Re: How would we copy an iterator?

2015-02-23 Thread Brendan Eich
Tab Atkins Jr. wrote: (Not saying anything needs to be added right now. Just pointing out the specifics, as it seemed you were talking past each other.) Thanks, I was thinking beyond tee as a generic, which copies (requiring a set-aside, could be a lot of memory). If the cliff leads to

Re: How would we copy an iterator?

2015-02-23 Thread Brendan Eich
Benjamin (Inglor) Gruenbaum wrote: Why not? The generator would switch on sent value, in a loop. Well, let's say we have an iterator that does nothing once, returns what was sent to it the first 5 times and then is done: ```js function* gen(){ var res = yield; for(var i = 0; i 5; i++){

Re: How would we copy an iterator?

2015-02-22 Thread Salvador de la Puente González
Hey Philip, you can see https://esdiscuss.org/topic/proposal-generator-clone-and-generator-goto for more about this topic. On Wed, Feb 18, 2015 at 2:02 PM, Philip Polkovnikov polkovnikov...@gmail.com wrote: - 1. Where is the function `run`? The function `run` is pretty classic variation on

Re: How would we copy an iterator?

2015-02-22 Thread Brendan Eich
As the comments from Tab Atkins and John Lenz there suggest, this is best done above the level of the standard, for now. If we need to roll up itertools including tee in ES7 (I am pretty sure we do), the best way to get there is via github -- not by prematurely standardizing APIs or

Re: How would we copy an iterator?

2015-02-22 Thread Salvador de la Puente González
Yep. This was already discussed in the topic I mentioned before. Just to remember, the real problem with tee() is that the generators are not actually independent as you can not .send() different information to each one to make them diverge. So producing a real clone of the generator is not

Re: How would we copy an iterator?

2015-02-18 Thread Philip Polkovnikov
1. Where is the function `run`? The function `run` is pretty classic variation on the code you would see in `Q` or `bluebird`. function run(gen) { return function (/* args */) { var args = Array.prototype.slice.call(arguments); var iter = gen.apply(args); (function step(arr) {

Re: How would we copy an iterator?

2015-02-18 Thread Philip Polkovnikov
- 1. Where is the function `run`? The function `run` is pretty classic variation on the code you would see in `Q` or `bluebird`. function run(gen) { return function (/* args */) { var args = Array.prototype.slice.call(arguments); var iter = gen.apply(args); (function step(arr) {

RE: How would we copy an iterator?

2015-02-13 Thread François REMY
For the record, I proposed this feature before, and it wasn't seen as a good idea, for some reason: https://esdiscuss.org/topic/function-is-not-mandatory#content-47 Given how close ES6 is to ship, I think it's too late to make such changes to the spec, we will have to live with it. Use Traceur

How would we copy an iterator?

2015-02-12 Thread Philip Polkovnikov
As pretty everyone already seen, generators are usually used in composition with promises to yield (pun intended) a plain simple linear code. This solution looks very much like monads from Haskell, yet in a better syntax: every a - b in Haskell is a = yield b in JS, and that aids to get rid of