{"version":3,"file":"union.cjs","names":["unique"],"sources":["../../src/array/union.ts"],"sourcesContent":["import unique from './unique';\n\n/**\n * Returns unique values in all the given collections.\n *\n * @param {unknown[][]} collections The arrays to union.\n * @param {Function} by The iteratee invoked per element.\n * @returns {unknown[]} A new array of combined unique values.\n *\n * @example\n * union([[1, 2], [2, 3]]) //=> [1, 2, 3]\n */\nexport default function union(\n  collections: unknown[][] = [],\n  by?: (val: unknown) => unknown,\n): unknown[] {\n  if (collections.length === 0) {\n    return [];\n  }\n\n  // Built by appending rather than by `reduce` with `concat`: the latter copies\n  // the whole accumulator on every step, which is quadratic in the total number\n  // of elements — a union over 100,000 of them took 3.6 seconds.\n  const flattened: unknown[] = [];\n\n  for (const collection of collections) {\n    if (Array.isArray(collection)) {\n      for (const value of collection) {\n        flattened.push(value);\n      }\n    } else {\n      // `concat` appended a non-array as a single value; keep that.\n      flattened.push(collection);\n    }\n  }\n\n  return unique(flattened, by);\n}\n"],"mappings":"+HAYA,SAAwB,EACtB,EAA2B,CAAC,EAC5B,EACW,CACX,GAAI,EAAY,SAAW,EACzB,MAAO,CAAC,EAMV,IAAM,EAAuB,CAAC,EAE9B,IAAK,IAAM,KAAc,EACvB,GAAI,MAAM,QAAQ,CAAU,EAC1B,IAAK,IAAM,KAAS,EAClB,EAAU,KAAK,CAAK,OAItB,EAAU,KAAK,CAAU,EAI7B,OAAOA,EAAAA,QAAO,EAAW,CAAE,CAC7B"}