Comprehensions, Where Art Thou?

Jason Orendorff jason.orendorff at
Mon Aug 11 07:14:57 PDT 2014

On Mon, Aug 11, 2014 at 8:49 AM, Andy Wingo <wingo at> wrote:
> Turns out, yes: you can do it by constructing a graph of combinators,
> with normal method syntax.  So you can do:
>   var sequence = iterable.lazy().if(somePredicate)
> where lazy and if might be:
>   Iterable.prototype.lazy = function* () {
>     for (var x of this) yield x;
>   }
>   Iterable.prototype.if = function* (pred) {
>     for (var x of this) if pred(x) yield x;
>   }

Dave Herman put together a repository showing a real program, adapted
from array comprehensions:
to using methods called .lazy(), .concat(), .map(), .filter(), and .flatMap():
but I don't understand what's going on there. Where are these methods
defined? Is it intended that .map() and .flatMap() will be defined on
all iterables?

If so, how? Didn't the committee also decide not to give Iterables or
Iterators a common prototype, or define these methods as part of the
Iterator or Iterable interface?


More information about the es-discuss mailing list