{"version":3,"file":"uniqueBy.js","names":[],"sources":["../src/uniqueBy.ts"],"sourcesContent":["import { purryFromLazy } from \"./internal/purryFromLazy\";\nimport type { BrandedReturn } from \"./internal/types/BrandedReturn\";\nimport type { Deduped } from \"./internal/types/Deduped\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\n\n/**\n * Returns a new array containing only one copy of each element in the original\n * list transformed by a function. Elements are compared by reference using Set.\n *\n * @param data - The array to filter.\n * @param keyFunction - Extracts a value that would be used to compare elements.\n * @signature\n *    uniqueBy(data, keyFunction)\n * @example\n *    uniqueBy(\n *     [{ n: 1 }, { n: 2 }, { n: 2 }, { n: 5 }, { n: 1 }, { n: 6 }, { n: 7 }],\n *     (obj) => obj.n,\n *    ) // => [{n: 1}, {n: 2}, {n: 5}, {n: 6}, {n: 7}]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function uniqueBy<T extends IterableContainer>(\n  data: T,\n  keyFunction: (item: T[number], index: number, data: T) => unknown,\n): Deduped<T>;\n\n/**\n * Returns a new array containing only one copy of each element in the original\n * list transformed by a function. Elements are compared by reference using Set.\n *\n * @param keyFunction - Extracts a value that would be used to compare elements.\n * @signature\n *    uniqueBy(keyFunction)(data)\n * @example\n *    pipe(\n *      [{n: 1}, {n: 2}, {n: 2}, {n: 5}, {n: 1}, {n: 6}, {n: 7}], // only 4 iterations\n *      uniqueBy(obj => obj.n),\n *      take(3)\n *    ) // => [{n: 1}, {n: 2}, {n: 5}]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function uniqueBy<T extends IterableContainer>(\n  keyFunction: (item: T[number], index: number, data: T) => unknown,\n): (data: T) => Deduped<T>;\n\nexport function uniqueBy(...args: readonly unknown[]): unknown {\n  return purryFromLazy(lazyImplementation, args);\n}\n\nfunction lazyImplementation<T>(\n  keyFunction: (item: T, index: number, data: readonly T[]) => unknown,\n): LazyEvaluator<T> {\n  // @see https://github.com/typescript-eslint/typescript-eslint/issues/9885\n  const brandedKeyFunction = keyFunction as BrandedReturn<typeof keyFunction>;\n\n  const set = new Set<ReturnType<typeof brandedKeyFunction>>();\n  return (value, index, data) => {\n    const key = brandedKeyFunction(value, index, data);\n    if (set.has(key)) {\n      return SKIP_ITEM;\n    }\n\n    set.add(key);\n    return { done: false, hasNext: true, next: value };\n  };\n}\n"],"mappings":"+FAkDA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAO,EAAc,EAAoB,EAAK,CAGhD,SAAS,EACP,EACkB,CAElB,IAAM,EAAqB,EAErB,EAAM,IAAI,IAChB,OAAQ,EAAO,EAAO,IAAS,CAC7B,IAAM,EAAM,EAAmB,EAAO,EAAO,EAAK,CAMlD,OALI,EAAI,IAAI,EAAI,CACP,GAGT,EAAI,IAAI,EAAI,CACL,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,EAAO"}