ts-prime
Version:
A utility library for JavaScript and Typescript.
21 lines • 1.13 kB
TypeScript
import { PredIndexed } from './_types';
/**
* Splits a collection into sets, grouped by the result of running each value through `fn`.
* @param items the items to group
* @param fn the grouping function
* @signature
* P.groupBy(array, fn)
* @signature
* P.groupBy(fn)(array)
* @example
* P.groupBy(['one', 'two', 'three'], x => x.length) // => {3: ['one', 'two'], 5: ['three']}
* P.pipe(['one', 'two', 'three'], P.groupBy(x => x.length)) // => {3: ['one', 'two'], 5: ['three']}
* @category Array, Pipe
*/
export declare function groupBy<T, K extends keyof any>(items: readonly T[], fn: (item: T) => K | ReadonlyArray<K>): Record<K, T[]>;
export declare function groupBy<T, K extends keyof any>(fn: (item: T) => K | ReadonlyArray<K>): (array: readonly T[]) => Record<K, T[]>;
export declare namespace groupBy {
function indexed<T, K extends keyof any>(array: readonly T[], fn: PredIndexed<T, K | ReadonlyArray<K>>): Record<K, T[]>;
function indexed<T, K extends keyof any>(fn: PredIndexed<T, K | ReadonlyArray<K>>): (array: readonly T[]) => Record<K, T[]>;
}
//# sourceMappingURL=groupBy.d.ts.map