//#region src/Array/indexBy.d.ts /** * # indexBy * * ```ts * function Array.indexBy( * target: readonly T[], * by: ( * value: NoInfer, * idx: number, * target: readonly NoInfer[], * ) => U, * ): Record * ``` * * Creates a record by indexing the `target` array using the `by` function to generate keys. Optionally transforms values using the `transform` function. * * ## Example * * ```ts [data-first] * import { Array } from "@monstermann/array"; * * const users = [ * { id: 1, name: "Alice" }, * { id: 2, name: "Bob" }, * ]; * * Array.indexBy(users, (user) => user.id); * // { 1: { id: 1, name: 'Alice' }, 2: { id: 2, name: 'Bob' } } * * Array.indexBy( * users, * (user) => user.id, * (user) => user.name, * ); // { 1: "Alice", 2: "Bob" } * ``` * * ```ts [data-last] * import { Array } from "@monstermann/array"; * * pipe( * users, * Array.indexBy((user) => user.id), * ); // { 1: { id: 1, name: 'Alice' }, 2: { id: 2, name: 'Bob' } } * * pipe( * users, * Array.indexBy( * (user) => user.id, * (user) => user.name, * ), * ); // { 1: "Alice", 2: "Bob" } * ``` * */ declare const indexBy: { (target: readonly T[], by: (value: NoInfer, idx: number, target: readonly NoInfer[]) => U, transform: (value: NoInfer, key: U, idx: number, target: readonly NoInfer[]) => V): Record; (target: readonly T[], by: (value: NoInfer, idx: number, target: readonly NoInfer[]) => U): Record; }; //#endregion export { indexBy };