export interface Identifiable { id: string; } export const groupById = ( acc: Record, value: T, ): Record => Object.assign(acc, { [value.id]: (acc[value.id] || []).concat(value), }); export const getGroupedMapById = ( array: T[], ): Record => array.reduce(groupById, {});