Skip to main content
Module

x/rimbu/mod.ts>AsyncReducer.groupBy

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Latest
variable AsyncReducer.groupBy
import { AsyncReducer } from "https://deno.land/x/rimbu@1.2.1/mod.ts";
const { groupBy } = AsyncReducer;

Returns an AsyncReducer that uses the valueToKey function to calculate a key for each value, and feeds the tuple of the key and the value to the collector reducer. Finally, it returns the output of the collector. If no collector is given, the default collector will return a JS multimap of the type Map<K, V[]>.

type

{ <T, K, R, T2 extends readonly [K, T] = [K, T]>(valueToKey: (value: T, index: number) => MaybePromise<K>, options: { collector: AsyncReducer.Accept<[K, T] | T2, R>; }): AsyncReducer<T, R>; <T, K>(valueToKey: (value: T, index: number) => MaybePromise<K>, options?: { collector?: undefined; }): AsyncReducer<T, Map<K, T[]>>; }

type

{ <T, K, R, T2 extends readonly [K, T] = [K, T]>(valueToKey: (value: T, index: number) => MaybePromise<K>, options: { collector: AsyncReducer.Accept<[K, T] | T2, R>; }): AsyncReducer<T, R>; <T, K>(valueToKey: (value: T, index: number) => MaybePromise<K>, options?: { collector?: undefined; }): AsyncReducer<T, Map<K, T[]>>; }