@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
11 lines • 419 B
JavaScript
import { accumulate } from './accumulate.js';
export function groupBy(propNameOrFn) {
const getKey = typeof propNameOrFn === 'function'
? propNameOrFn
: (chunk) => chunk[propNameOrFn].toString();
return accumulate({}, (acc, chunk) => {
const key = getKey(chunk);
return { ...acc, [key]: key in acc ? [...acc[key], chunk] : [chunk] };
});
}
//# sourceMappingURL=groupBy.js.map