Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

function groupBy is weired #13

Open
HaskellZhangSong opened this issue May 29, 2015 · 1 comment
Open

function groupBy is weired #13

HaskellZhangSong opened this issue May 29, 2015 · 1 comment

Comments

@HaskellZhangSong
Copy link

No description provided.

@harry75369
Copy link

groupBy will not function correctly if key is an array. Since getHashCode of the Dictionary implementation in l2o.js will not compare two arrays by values. One possible hack is to convert array into string first, as the following shows

var Ix = require('ix');

var xs = Ix.Enumerable.fromArray([
  ['hangzhou','2003'],
  ['hangzhou','2003'],
  ['shenzhen','2013'],
  ['shenzhen','2013']
]);

var printEnumerable = function(e) {
  e.forEach(function(x){console.log(x);});
};

var t = xs.groupBy(function(x) {
    //return [x[0],x[1]]; // wrong
    /* output:
    { key: [ 'hangzhou', '2003', getHashCode: [Function] ],
      values: [ [ 'hangzhou', '2003' ] ] }
    { key: [ 'hangzhou', '2003', getHashCode: [Function] ],
      values: [ [ 'hangzhou', '2003' ] ] }
    { key: [ 'shenzhen', '2013', getHashCode: [Function] ],
      values: [ [ 'shenzhen', '2013' ] ] }
    { key: [ 'shenzhen', '2013', getHashCode: [Function] ],
      values: [ [ 'shenzhen', '2013' ] ] }
    */

    return ""+[x[0],x[1]]; // correct
    /* output:
    { key: 'hangzhou,2003',
      values: [ [ 'hangzhou', '2003' ], [ 'hangzhou', '2003' ] ] }
    { key: 'shenzhen,2013',
      values: [ [ 'shenzhen', '2013' ], [ 'shenzhen', '2013' ] ] }
    */
}, function(x) {
    return x;
}, function(key, values) {
    var res = {};
    res['key'] = key;
    res['values'] = values.toArray();
    return res;
});

printEnumerable(t)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants