`.toArray()` for all generators

Forbes Lindesay forbes at lindesay.co.uk
Wed Aug 28 08:27:30 PDT 2013


The thing about `.map` and `.filter` is that it would be easy enough to create functional versions:

```js
function* map(array, fn) {
  for (var x of array) {
    yield fn(x)
  }
}
```

But harder to create methods:

```js
Iteratable.prototype.map = function(fn) {
  for (var x of this) {
    yield fn(x)
  }
}
```

The reason being that not all iteratables share a prototype (to my knowledge). 



More information about the es-discuss mailing list