Maps with object keys

2014-02-17 Thread Benjamin (Inglor) Gruenbaum
I'm trying to work with ES6 Map objects and I ran into an interesting problem. I want to index/group based on several key values. Let's say my original data is something like: ```js [{x:3,y:5,z:3},{x:3,y:4,z:4},{x:3,y:4,z:7},{x:3,y:1,z:1},{x:3,y:5,z:4}] ``` I want to group it based on the x

Re: Maps with object keys

2014-02-17 Thread Bradley Meck
I understand the capability of python, but that is done through comprehensions that do not relate to the mapping of key to value. In ES6 the syntax comes out to: ``` let tuple = {x:3,y:5} [for (value of map.entries()) if (Object.keys(tuple).every((tupleKey)=tuple[tupleKey] == value[tupleKey]))

Re: Maps with object keys

2014-02-17 Thread Benjamin (Inglor) Gruenbaum
My issue here is that I want to index on complex values. I was under the impression ES6 maps solve amongst others the problem that with objects - keys are only strings. I want to index on 2 (or 100) properties - in this example the x and y values. I don't want to iterate the whole collection and

Re: Maps with object keys

2014-02-17 Thread C. Scott Ananian
It is straightforward to implement a hash function based map as a subclass of `Map`. Something like: ```js var HashMap = function() { this._map = new Map(); }; HashMap.set = function(key, value) { var hash = key.hashCode(); var list = this._map.get(hash); if (!list) { list = [];

Re: Maps with object keys

2014-02-17 Thread David Bruant
Le 17/02/2014 22:55, Benjamin (Inglor) Gruenbaum a écrit : My issue here is that I want to index on complex values. I was under the impression ES6 maps solve amongst others the problem that with objects - keys are only strings. With maps, all native types (string, number, boolean, undefined,

Re: Maps with object keys

2014-02-17 Thread Jason Orendorff
On Mon, Feb 17, 2014 at 3:09 PM, Benjamin (Inglor) Gruenbaum ing...@gmail.com wrote: I'm trying to work with ES6 Map objects and I ran into an interesting problem. Yes! Well done. We've noticed this too, and considered (a) allowing objects to provide their own hash and equals operations, as in

Re: Maps with object keys

2014-02-17 Thread Benjamin (Inglor) Gruenbaum
Thanks, I was starting to feel like I wasn't explaining my issue very well given the other replies. I'm glad we agree this is not something user-code should have to shim for language level collections. I'm working on several projects that perform statistical analysis and I wanted to stick to