sequency
Version:
Functional sequences for processing iterable data in JavaScript
29 lines • 938 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.GroupBy = void 0;
var GroupBy = /** @class */ (function () {
function GroupBy() {
}
/**
* Groups all elements of the sequence into a map. Keys are determined by the given `keySelector` function.
*
* @param {(value: T) => K} keySelector
* @returns {Map<K, Array<T>>}
*/
GroupBy.prototype.groupBy = function (keySelector) {
var result = new Map();
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
var key = keySelector(item.value);
var array = result.get(key);
if (array == null) {
result.set(key, [item.value]);
}
else {
array.push(item.value);
}
}
return result;
};
return GroupBy;
}());
exports.GroupBy = GroupBy;
//# sourceMappingURL=groupBy.js.map