@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
15 lines • 586 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.groupBy = void 0;
const accumulate_1 = require("@johngw/stream/transformers/accumulate");
function groupBy(propNameOrFn) {
const getKey = typeof propNameOrFn === 'function'
? propNameOrFn
: (chunk) => chunk[propNameOrFn].toString();
return (0, accumulate_1.accumulate)({}, (acc, chunk) => {
const key = getKey(chunk);
return { ...acc, [key]: key in acc ? [...acc[key], chunk] : [chunk] };
});
}
exports.groupBy = groupBy;
//# sourceMappingURL=groupBy.js.map