import { groupBy } from 'lodash'; export const transformToMapBy = ( collection: T[], key: keyof T, ): Map => { return new Map(Object.entries(groupBy(collection, key))); };