Re: Map: filter/map and more

2014-11-28 Thread Andy Wingo
On Thu 20 Nov 2014 01:49, Dmitry Soshnikov dmitry.soshni...@gmail.com writes: At the meeting it was decided not to go with `map` and `filter` sitting on `Map.prototype`, but instead to use iterators in the way like: ``` map .entries() // returns an iterator .map((v, k, m) = { ... })

RE: Map: filter/map and more

2014-11-28 Thread Domenic Denicola
From: Andy Wingo [mailto:wi...@igalia.com] Is there a nice way to do this for the default iterator? https://esdiscuss.org/topic/map-filter-map-and-more#content-57 Also, I thought that map, filter, and such were to be on the Iterator.prototype. That precludes multi-arg map functions

Re: Map: filter/map and more

2014-11-20 Thread Tab Atkins Jr.
On Wed, Nov 19, 2014 at 4:49 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: (For the history of this thread to refer to it later) At the meeting it was decided not to go with `map` and `filter` sitting on `Map.prototype`, but instead to use iterators in the way like: ``` map

Re: Map: filter/map and more

2014-11-20 Thread Axel Rauschmayer
At the meeting it was decided not to go with `map` and `filter` sitting on `Map.prototype`, but instead to use iterators in the way like: ``` map .entries() // returns an iterator .map((v, k, m) = { ... }) .filter((v, k, m) = { ... }) .collect(); // returns a new map after all

Re: Map: filter/map and more

2014-11-20 Thread Mark Volkmann
Where can I read about the rationale to not put those methods on the Map prototype? I'm curious why that was okay for the Array class, but not okay for Map and Set. On Thu, Nov 20, 2014 at 12:32 PM, Axel Rauschmayer a...@rauschma.de wrote: At the meeting it was decided not to go with `map` and

Re: Map: filter/map and more

2014-11-20 Thread Tab Atkins Jr.
On Thu, Nov 20, 2014 at 10:32 AM, Axel Rauschmayer a...@rauschma.de wrote: At the meeting it was decided not to go with `map` and `filter` sitting on `Map.prototype`, but instead to use iterators in the way like: ``` map .entries() // returns an iterator .map((v, k, m) = { ... })

RE: Map: filter/map and more

2014-11-20 Thread Domenic Denicola
From: Tab Atkins Jr. [mailto:jackalm...@gmail.com] 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,

Re: Map: filter/map and more

2014-11-20 Thread Axel Rauschmayer
On 20 Nov 2014, at 1:49 , Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: (For the history of this thread to refer to it later) At the meeting it was decided not to go with `map` and `filter` sitting on `Map.prototype`, but instead to use iterators in the way like: ``` map

RE: Map: filter/map and more

2014-11-20 Thread Domenic Denicola
From: Axel Rauschmayer [mailto:a...@rauschma.de] Question – shouldn’t this example be written as follows? Yes. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Map: filter/map and more

2014-11-20 Thread Tab Atkins Jr.
On Thu, Nov 20, 2014 at 10:42 AM, Domenic Denicola d...@domenic.me wrote: From: Tab Atkins Jr. [mailto:jackalm...@gmail.com] 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?

RE: Map: filter/map and more

2014-11-20 Thread Domenic Denicola
From: Tab Atkins Jr. [mailto:jackalm...@gmail.com] Interesting idea, but I'm not sure how it's supposed to work in practice. Doesn't answer all of your questions, and is probably half-assed in various ways, but here is some stuff that we came up with in some live-coding during the meeting:

Re: Map: filter/map and more

2014-11-19 Thread Dmitry Soshnikov
(For the history of this thread to refer to it later) At the meeting it was decided not to go with `map` and `filter` sitting on `Map.prototype`, but instead to use iterators in the way like: ``` map .entries() // returns an iterator .map((v, k, m) = { ... }) .filter((v, k, m) = { ... })

Re: Map: filter/map and more

2014-11-17 Thread Dmitry Soshnikov
Is this something what is ready for discussion on a meeting (in particular, tomorrow's meeting)? Regardless, whether the `map` and `set` will be directly on the `Map.prototype` or on some generic `%CollectionPrototype%`, the user-level API will stay the same, right? And will be used as: ```

Re: Map: filter/map and more

2014-11-17 Thread Brendan Eich
Dmitry Soshnikov wrote: Is this something what is ready for discussion on a meeting (in particular, tomorrow's meeting)? You put something on the agenda, cool. https://github.com/tc39/agendas/blob/master/2014/11.md /be ___ es-discuss mailing list

Re: Map: filter/map and more

2014-10-08 Thread Dmitry Soshnikov
On Mon, Oct 6, 2014 at 9:37 AM, Brendan Eich bren...@mozilla.org wrote: Brendan Eich wrote: This meansMap.prototype.mapetc. -- or %ItereablePrototype%.map if not Array.prototype.map etc. -- are the eager collection-generic companions. Bear with me, trying to develop a half-thought. To say

Re: Map: filter/map and more

2014-10-08 Thread Brendan Eich
Dmitry Soshnikov wrote: The Collection protocol thus consists of at least .constructor, @@iterator, .set. (Is there a better way to clone? Don't want a new protocol where an old one will suffice!) This Collection protocol would include Map and maplikes but leaves out Set, Array,

Re: Map: filter/map and more

2014-10-08 Thread Dmitry Soshnikov
On Wed, Oct 8, 2014 at 3:09 PM, Brendan Eich bren...@mozilla.org wrote: Dmitry Soshnikov wrote: The Collection protocol thus consists of at least .constructor, @@iterator, .set. (Is there a better way to clone? Don't want a new protocol where an old one will suffice!) This

Re: Map: filter/map and more

2014-10-07 Thread Kevin Smith
[1]:http://wiki.ecmascript.org/doku.php?id=strawman:bind_operator Problem is :: vs. just dot, and now you have two problems. I'm actually good with FP inside-out, could learn to love :: if we add it, but the main objection IMHO is two-problems. OOP means just dot. That reminds me:

Re: Map: filter/map and more

2014-10-07 Thread Andrea Giammarchi
Coming form other languages, double colons is used as a static thing, although we don't need (?) this convention in ES6 classes, and I agree it looks ugly anyway. I wonder if here `:` would work instead, because I'd personally find any other usage of the thin arrow `-` confusing * Regards * I

Re: Map: filter/map and more

2014-10-07 Thread Tab Atkins Jr.
On Sat, Oct 4, 2014 at 10:03 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: This case I'd probably make as `Map#mapWithKey`, however there other questions arise like, should the returned pair replace the existing, or create a new one, if the key is different? ``` ({a =

Re: Map: filter/map and more

2014-10-07 Thread Kevin Smith
* I personally see `-` as a shortcut for `function` I'm a C sympathizer, so I don't see it the quite the same, but I understand. Regardless of the token, I feel like a generalized ref_get/set mechanism would be great. ___ es-discuss mailing list

Re: Map: filter/map and more

2014-10-07 Thread Mark S. Miller
On Tue, Oct 7, 2014 at 8:51 AM, Kevin Smith zenpars...@gmail.com wrote: [1]:http://wiki.ecmascript.org/doku.php?id=strawman:bind_operator Problem is :: vs. just dot, and now you have two problems. I'm actually good with FP inside-out, could learn to love :: if we add it, but the main

Re: Map: filter/map and more

2014-10-07 Thread Kevin Smith
My question is: If we have -, how much need would there still be for :: or @? If - can subsume the practical need for either or both of the others, that would be interesting. That was the idea, but it's been a while since I went through that exercise. I need to review.

Re: Map: filter/map and more

2014-10-07 Thread Dmitry Soshnikov
On Sat, Oct 4, 2014 at 10:03 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Sat, Oct 4, 2014 at 5:58 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Domenic Denicola Unless I'm missing something

Re: Map: filter/map and more

2014-10-06 Thread Brendan Eich
Brendan Eich wrote: This meansMap.prototype.mapetc. -- or %ItereablePrototype%.map if not Array.prototype.map etc. -- are the eager collection-generic companions. Bear with me, trying to develop a half-thought. To say it with code: ```js Object.defineProperty(%IteratorPrototype%, 'map', {

Re: Map: filter/map and more

2014-10-06 Thread Brendan Eich
Caffeinating still, obvious bugfix below: Brendan Eich wrote: ```js Object.defineProperty(%CollectionPrototype%, 'map', { value: function (fun) { let result = new this.constructor(); for (let [key, val] of this) { result.set(key, val); ```js

RE: Map: filter/map and more

2014-10-06 Thread Domenic Denicola
Note the this.clone() call. This is novel, and required to avoid exhausting the receiver iterator. This is noteworthy and worth keeping in mind regardless of the rest of the discussion. I think I would be fine having %IterablePrototype%.map exhaust the iterator. I would `.clone()` manually

Re: Map: filter/map and more

2014-10-06 Thread Brendan Eich
Domenic Denicola wrote: Note the this.clone() call. This is novel, and required to avoid exhausting the receiver iterator. This is noteworthy and worth keeping in mind regardless of the rest of the discussion. I think I would be fine having %IterablePrototype%.map exhaust the iterator. I

RE: Map: filter/map and more

2014-10-06 Thread Domenic Denicola
From: Brendan Eich [mailto:bren...@mozilla.org] For iteration, sure. For map or other functional (pure?!) APIs? Yikes. If in ES7 we build up the duality between iterables and observables, add for-on, pave the way toward FRP, then `map` as a protocol (part) should be pure with respect to

Re: Map: filter/map and more

2014-10-06 Thread Jason Orendorff
On Mon, Oct 6, 2014 at 1:34 PM, Domenic Denicola dome...@domenicdenicola.com wrote: This is iterables vs. iterators IMO. Iterators are inherently stateful and I'd expect anything that uses them to consume them, even something named map. Iterables of course would not be. I agree. It's

Re: Map: filter/map and more

2014-10-06 Thread Brendan Eich
Good to known (and I had heard this via Python community channels already). Still feels wrong, given name polymorphism on `map`. Perhaps we just plow ahead. Still seems like someone (at some layer) will want iter.clone(). Vouch? /be Jason Orendorff wrote: OnMon, Oct 6, 2014 at 1:34 PM,

Re: Map: filter/map and more

2014-10-05 Thread Dmitry Soshnikov
On Sat, Oct 4, 2014 at 10:03 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Sat, Oct 4, 2014 at 5:58 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Domenic Denicola Unless I'm missing something

RE: Map: filter/map and more

2014-10-05 Thread Domenic Denicola
From: Brendan Eich [mailto:bren...@mozilla.org] But entries returns an iterator, and if we define %IteratorPrototype% to create a new instance of the right class given its |this| parameter, in this case Map and not MapIterator, then no need for the new Map() wrapper. This seems like it'd

Re: Map: filter/map and more

2014-10-05 Thread Brendan Eich
Domenic Denicola wrote: From: Brendan Eich [mailto:bren...@mozilla.org] But entries returns an iterator, and if we define %IteratorPrototype% to create a new instance of the right class given its|this| parameter, in this case Map and not MapIterator, then no need for the new Map()

RE: Map: filter/map and more

2014-10-04 Thread Domenic Denicola
From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Dmitry Soshnikov Thanks, done. https://github.com/tc39/ecma262/pull/13 This seems less useful than adding %IteratorPrototype%.map and %IteratorPrototype.filter. It also clarifies some of the confusion about whether you are

RE: Map: filter/map and more

2014-10-04 Thread Domenic Denicola
From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Domenic Denicola Unless I'm missing something (quite possible!), I would prefer not to add new methods to Map and Set when they could be added to %IteratorPrototype%. Yeah, I'm missing something. It's the difference in

Re: Map: filter/map and more

2014-10-04 Thread Dmitry Soshnikov
On Sat, Oct 4, 2014 at 5:58 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Domenic Denicola Unless I'm missing something (quite possible!), I would prefer not to add new methods to Map and Set when they could be

Re: Map: filter/map and more

2014-10-04 Thread Brendan Eich
Dmitry Soshnikov wrote: From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Domenic Denicola - show quoted text - Unless I'm missing something (quite possible!), I would prefer not to add new methods to Map and Set when they could be added to %IteratorPrototype%. Yeah,

Re: Map: filter/map and more

2014-10-02 Thread Rick Waldron
On Wed, Oct 1, 2014 at 6:33 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Wed, Oct 1, 2014 at 1:26 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Wed, Oct 1, 2014 at 12:59 PM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 3:51 PM, Jeremy

Re: Map: filter/map and more

2014-10-02 Thread Dmitry Soshnikov
On Thu, Oct 2, 2014 at 12:00 PM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 6:33 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Wed, Oct 1, 2014 at 1:26 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Wed, Oct 1, 2014 at 12:59 PM, Rick

Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
Hi, (Maps are awesome!) 1. Transforming iteration methods We're currently polyfillying the `Map`, and got some questions form devs. One of them is about transforming iteration methods, like `map` and `filter`. Unfortunately I missed that part of the spec when it was approved, so can someone

Re: Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
On Wed, Oct 1, 2014 at 11:57 AM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 2:50 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: Hi, (Maps are awesome!) 1. Transforming iteration methods We're currently polyfillying the `Map`, and got some questions form

Re: Map: filter/map and more

2014-10-01 Thread Axel Rauschmayer
Then thing is: if we'd like to use maps for such use-case, it brings us back to that inconvenient imperative style of assignments (even worse, since you have to repeat that `.set(...)` constantly): ``` var requestData = new Map(); requestData.set(Names.ID, id);

Re: Map: filter/map and more

2014-10-01 Thread Jeremy Martin
Not sure if this is sufficient motivation to accelerate the timeline for adding suitable parallels from Array.prototype, but it may be worth recalling what developers did last time there were obvious gaps in what a native prototype provided. Array#contains, anyone? On Wed, Oct 1, 2014 at 3:28

Re: Map: filter/map and more

2014-10-01 Thread Rick Waldron
On Wed, Oct 1, 2014 at 3:51 PM, Jeremy Martin jmar...@gmail.com wrote: Not sure if this is sufficient motivation to accelerate the timeline It's not about motivation, it's about realistic time constraints. TC39 has already had to push out 6 months and that was not taken well by both the

Re: Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
On Wed, Oct 1, 2014 at 12:59 PM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 3:51 PM, Jeremy Martin jmar...@gmail.com wrote: Not sure if this is sufficient motivation to accelerate the timeline It's not about motivation, it's about realistic time constraints. TC39

Re: Map: filter/map and more

2014-10-01 Thread Rick Waldron
On Wed, Oct 1, 2014 at 3:51 PM, Jeremy Martin jmar...@gmail.com wrote: Not sure if this is sufficient motivation to accelerate the timeline for adding suitable parallels from Array.prototype, but it may be worth recalling what developers did last time there were obvious gaps in what a native

Re: Map: filter/map and more

2014-10-01 Thread Rick Waldron
On Wed, Oct 1, 2014 at 4:17 PM, Axel Rauschmayer a...@rauschma.de wrote: On Oct 1, 2014, at 22:12 , Axel Rauschmayer a...@rauschma.de wrote: 1. Transforming iteration methods We're currently polyfillying the `Map`, and got some questions form devs. One of them is about transforming

Re: Map: filter/map and more

2014-10-01 Thread Axel Rauschmayer
Ah, thanks! Then I’d wrap the result of `entries()` in `Array.from()`. In ES7, we’ll hopefully be able to use comprehensions or iterator helper functions. On Oct 1, 2014, at 22:27 , Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 4:17 PM, Axel Rauschmayer

Re: Map: filter/map and more

2014-10-01 Thread Kevin Smith
```js let map2 = new Map(map1.entries().filter((key, value) = key = 0)); let map2 = new Map(map1.entries().map((key, value) = [key * 2, value * 2])); entries() returns an iterator, not an array. let map2 = new Map([...map1].map(([k, v]) = [k, v * 2])

Re: Map: filter/map and more

2014-10-01 Thread Brendan Eich
Kevin Smith wrote: entries() returns an iterator, not an array. let map2 = new Map([...map1].map(([k, v]) = [k, v * 2]) Sweet! /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Map: filter/map and more

2014-10-01 Thread Rick Waldron
On Wed, Oct 1, 2014 at 4:38 PM, Axel Rauschmayer a...@rauschma.de wrote: Ah, thanks! Then I’d wrap the result of `entries()` in `Array.from()`. In ES7, we’ll hopefully be able to use comprehensions or iterator helper functions. Don't need to do that either. let map1 = new Map([[-1, -1], [0,

Re: Map: filter/map and more

2014-10-01 Thread Rick Waldron
On Wed, Oct 1, 2014 at 4:41 PM, Kevin Smith zenpars...@gmail.com wrote: ```js let map2 = new Map(map1.entries().filter((key, value) = key = 0)); let map2 = new Map(map1.entries().map((key, value) = [key * 2, value * 2])); entries() returns an iterator, not an array. let map2 = new

Re: Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
On Wed, Oct 1, 2014 at 1:26 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Wed, Oct 1, 2014 at 12:59 PM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 3:51 PM, Jeremy Martin jmar...@gmail.com wrote: Not sure if this is sufficient motivation to accelerate

Re: Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
On Wed, Oct 1, 2014 at 12:28 PM, Axel Rauschmayer a...@rauschma.de wrote: Then thing is: if we'd like to use maps for such use-case, it brings us back to that inconvenient imperative style of assignments (even worse, since you have to repeat that `.set(...)` constantly): ``` var

Re: Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
On Wed, Oct 1, 2014 at 1:38 PM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 4:26 PM, Dmitry Soshnikov dmitry.soshni...@gmail.com wrote: On Wed, Oct 1, 2014 at 12:59 PM, Rick Waldron waldron.r...@gmail.com wrote: On Wed, Oct 1, 2014 at 3:51 PM, Jeremy Martin

Re: Map: filter/map and more

2014-10-01 Thread Brendan Eich
Dmitry Soshnikov wrote: Not ideal either. Usually langs provide nice declarative syntax for such things. E.g. we have[1] the same in the HACK language, and use it well everyday when need a map. But this part is of course not for ES6, hope ES7-ish. [1]

Re: Map: filter/map and more

2014-10-01 Thread Dmitry Soshnikov
On Wed, Oct 1, 2014 at 4:51 PM, Brendan Eich bren...@mozilla.org wrote: Dmitry Soshnikov wrote: Not ideal either. Usually langs provide nice declarative syntax for such things. E.g. we have[1] the same in the HACK language, and use it well everyday when need a map. But this part is of

Re: Map: filter/map and more

2014-10-01 Thread Axel Rauschmayer
We could definitely have Map and Set literals: const map = {1 = one, two = true, false = three}; Would that be tricky to parse if keys can be arbitrary expressions (incl. array literals)? const set = {1, two, false}; If you still buy Harmony of My Dreams, prefix # before { to get

Re: Map: filter/map and more

2014-10-01 Thread Brendan Eich
Axel Rauschmayer wrote: We could definitely have Map and Set literals: const map = {1 = one, two = true, false = three}; Would that be tricky to parse if keys can be arbitrary expressions (incl. array literals)? The issue would be arrow function expression keys: const map = {x = x*x =