/** Similar to lodash keyBy */ export const keyBy = ( list: T[], getKey: (item: T) => K, ) => list.reduce( (previous, currentItem) => { const group = getKey(currentItem); return { ...previous, [group]: currentItem }; }, {} as Record, );