Note that an equivalent of both `.map` and `.filter` already exists in ES6: its
name is "generator expression". For instance:
```
array.filter(pred).map(transf)
```
becomes:
```
(for (let x of iter) if (pred(x)) transf(x))
```
—Claude
Le 28 août 2013 à 17:27, Forbes Lindesay <[email protected]> a écrit :
> 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).
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss