ts-prime
Version:
A utility library for JavaScript and Typescript.
23 lines • 976 B
TypeScript
import { PredIndexed } from './_types';
/**
* Converts a list of objects into an object indexing the objects by the given key.
* @param array the array
* @param fn the indexing function
* @signature
* P.indexBy(array, fn)
* P.indexBy(fn)(array)
* @example
* P.indexBy(['one', 'two', 'three'], x => x.length) // => {3: 'two', 5: 'three'}
* P.pipe(
* ['one', 'two', 'three'],
* P.indexBy(x => x.length)
* ) // => {3: 'two', 5: 'three'}
* @category Array, Pipe
*/
export declare function indexBy<T>(array: readonly T[], fn: (item: T) => any): Record<string, T>;
export declare function indexBy<T>(fn: (item: T) => string | number): (array: readonly T[]) => Record<string, T>;
export declare namespace indexBy {
function indexed<T, K>(array: readonly T[], fn: PredIndexed<T, any>): Record<string, T>;
function indexed<T, K>(fn: PredIndexed<T, any>): (array: readonly T[]) => Record<string, T>;
}
//# sourceMappingURL=indexBy.d.ts.map