UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

11 lines 442 B
import { accumulate } from '@johngw/stream/transformers/accumulate'; 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