UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

34 lines 1.15 kB
import type { PickByValue } from '@johngw/stream-common/Object'; import type { Stringable } from '@johngw/stream-common/String'; /** * Accumulates each chunk into an object where the key is the result of * calling a provided function or using a chunk's property. * * The key can be the result of a property on the chunk. * * @group Transformers * @see {@link label:function} * @example * ``` * --one------------two------------------three----------------------------- * * groupBy('length') * * --{'3':['one']}--{'3',['one','two']}--{'3':['one','two'],'5':['three']}- * ``` */ export declare function groupBy<T, K extends keyof PickByValue<T, Stringable>>(propName: K): TransformStream<T, Record<string, T[]>>; /** * The key can be the result of calling a provided function. * * @example * ``` * --6.1----------4.2--------------------6.3------------------------ * * groupBy(Math.floor) * * --{'6':[6.1]}--{'4':[4.2],'6':[6.1]}--{'4':[4.2],'6':[6.1,6.3]}-- * ``` */ export declare function groupBy<T, G extends Stringable>(propName: (chunk: T) => G): TransformStream<T, Record<string, T[]>>; //# sourceMappingURL=groupBy.d.ts.map