{"version":3,"sources":["../../src/functions/groupBy/groupBy.ts"],"names":[],"mappings":";AAMO,SAAS,QACd,OACA,QACA;AACA,UAAQ,SAAS,CAAC,GAAG,OAAO,CAAC,aAAa,gBAAgB;AACxD,UAAM,MAAM,OAAO,WAAW;AAG9B,gBAAY,GAAG,MAAM,CAAC;AAEtB,gBAAY,GAAG,EAAG,KAAK,WAAW;AAElC,WAAO;AAAA,EACT,GAAG,CAAC,CAA4B;AAClC","sourcesContent":["import { Maybe } from '../../types';\n\n/**\n * Takes an array and returns an object with the keys of the array\n * mapped to the items of the array\n */\nexport function groupBy<T, K extends string>(\n  array: Maybe<readonly T[]>,\n  getter: (item: T) => K\n) {\n  return (array ?? []).reduce((draftGroups, currentItem) => {\n    const key = getter(currentItem);\n\n    // eslint-disable-next-line no-param-reassign\n    draftGroups[key] ??= [];\n    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n    draftGroups[key]!.push(currentItem);\n\n    return draftGroups;\n  }, {} as Partial<Record<K, T[]>>);\n}\n"]}