Map: filter/map and more

Domenic Denicola d at
Thu Nov 20 10:42:42 PST 2014

From: Tab Atkins Jr. [mailto:jackalmage at] 

> Sounds good!  (I always end up calling one of the iterators on python dicts anyway, since I can never remember what the default iterator behavior is.)

Yeah. There is a separate idea that we should probably define Map.prototype.{map, filter, etc.} as behaving the same way as the default iterator (which in this case is .entries()). There's a few ideas on how to do this, e.g. specialized Map methods, or put a "Collection prototype" between Map.prototype and Object.prototype that generically delegates to the default iterator, or...

> I presume that .collect() expects an iterator of [k,v] pairs or something?  Also: this is the first I've heard of .collect().  I presume that'll show up in the spec?

The idea of .collect() is that when the iterator is created, it's told how to collect; in this case it would be using `new Map` I think. (Although there was talk of `Map.from` at the meeting, which I guess would be an additional API.) Since the iterator in this example does yield [k, v] pairs, and `new Map` accepts an iterable of `[k, v]` pairs, this will work nicely.

But yes, right now %IteratorPrototype% is entirely empty as just a placeholder for ES6. It needs map, filter, forEach, reduce, as well as collect. Design work to be done :)

More information about the es-discuss mailing list