typedash
Version:
modern, type-safe collection of utility functions
33 lines (32 loc) • 928 B
TypeScript
import { t as Maybe } from "./Maybe-pvX1mStM.js";
//#region src/functions/groupBy/groupBy.d.ts
/**
* Takes an array and returns an object with the keys of the array mapped to the items of the array.
* @param array The array to iterate over.
* @param getter The function used to extract the key from each element.
* @returns An object with the keys mapped to the elements.
* @example
* ```ts
* groupBy(
* [
* { id: 'a', value: 1 },
* { id: 'b', value: 1 },
* { id: 'c', value: 2 },
* ],
* (item) => item.value
* )
* // {
* // 1: [
* // { id: 'a', value: 1 },
* // { id: 'b', value: 1 },
* // ],
* // 2: [
* // { id: 'c', value: 2 },
* // ],
* // }
* ```
*/
declare function groupBy<T, K extends string>(array: Maybe<readonly T[]>, getter: (item: T) => K): Partial<Record<K, T[]>>;
//#endregion
export { groupBy as t };
//# sourceMappingURL=groupBy-CUndozSk.d.ts.map