I have several groupings I need to do today and find myself having a hard time finding a good way to do this in ReasonML. Here’s how I would group something in JS:
var groupBy = function(xs, keyFn) {
return xs.reduce(function(rv, x) {
const key = keyFn(x);
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
console.log(groupBy(['one', 'two', 'three'], x=> x.length));
// => {3: ["one", "two"], 5: ["three"]}