{"version":3,"file":"partition.cjs","names":["purry"],"sources":["../src/partition.ts"],"sourcesContent":["import type { FilteredArray } from \"./internal/types/FilteredArray\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { NonRefinedFilteredArray } from \"./internal/types/NonRefinedFilteredArray\";\nimport type { Not } from \"./internal/types/Not\";\nimport { purry } from \"./purry\";\n\n/**\n * Splits a collection into two groups, the first of which contains elements the\n * `predicate` type guard passes, and the second one containing the rest.\n *\n * @param data - The items to split.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to add the element to the first partition, and `false`\n * to add the element to the other partition. A type-predicate can also be used\n * to narrow the result.\n * @returns A 2-tuple of arrays where the first array contains the elements that\n * passed the predicate, and the second array contains the elements that did\n * not. The items are in the same order as they were in the original array.\n * @signature\n *    partition(data, predicate)\n * @example\n *    partition(\n *      ['one', 'two', 'forty two'],\n *      x => x.length === 3,\n *    ); // => [['one', 'two'], ['forty two']]\n * @dataFirst\n * @category Array\n */\nexport function partition<T extends IterableContainer, Condition>(\n  data: T,\n  predicate: (value: T[number], index: number, data: T) => value is Condition,\n): [\n  FilteredArray<T, Condition>,\n  FilteredArray<T, Condition, true /* IsNegated */>,\n];\n\nexport function partition<\n  T extends IterableContainer,\n  IsItemIncluded extends boolean,\n>(\n  data: T,\n  predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): [\n  NonRefinedFilteredArray<T, IsItemIncluded>,\n  NonRefinedFilteredArray<T, Not<IsItemIncluded>>,\n];\n\n/**\n * Splits a collection into two groups, the first of which contains elements the\n * `predicate` type guard passes, and the second one containing the rest.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to add the element to the first partition, and `false`\n * to add the element to the other partition. A type-predicate can also be used\n * to narrow the result.\n * @returns A 2-tuple of arrays where the first array contains the elements that\n * passed the predicate, and the second array contains the elements that did\n * not. The items are in the same order as they were in the original array.\n * @signature\n *    partition(predicate)(data)\n * @example\n *    pipe(\n *      ['one', 'two', 'forty two'],\n *      partition(x => x.length === 3),\n *    ); // => [['one', 'two'], ['forty two']]\n * @dataLast\n * @category Array\n */\nexport function partition<T extends IterableContainer, Condition>(\n  predicate: (value: T[number], index: number, data: T) => value is Condition,\n): (\n  data: T,\n) => [\n  FilteredArray<T, Condition>,\n  FilteredArray<T, Condition, true /* IsNegated */>,\n];\n\nexport function partition<\n  T extends IterableContainer,\n  IsItemIncluded extends boolean,\n>(\n  predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): (\n  data: T,\n) => [\n  NonRefinedFilteredArray<T, IsItemIncluded>,\n  NonRefinedFilteredArray<T, Not<IsItemIncluded>>,\n];\n\nexport function partition(...args: readonly unknown[]): unknown {\n  return purry(partitionImplementation, args);\n}\n\nconst partitionImplementation = <T, S extends T>(\n  data: readonly T[],\n  predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): [S[], T[]] => {\n  const ret: [S[], T[]] = [[], []];\n  for (const [index, item] of data.entries()) {\n    if (predicate(item, index, data)) {\n      ret[0].push(item);\n    } else {\n      ret[1].push(item);\n    }\n  }\n  return ret;\n};\n"],"mappings":"kGAyFA,SAAgB,EAAU,GAAG,EAAmC,CAC9D,OAAOA,EAAAA,MAAM,EAAyB,CAAI,CAC5C,CAEA,MAAM,GACJ,EACA,IACe,CACf,IAAM,EAAkB,CAAC,CAAC,EAAG,CAAC,CAAC,EAC/B,IAAK,GAAM,CAAC,EAAO,KAAS,EAAK,QAAQ,EACnC,EAAU,EAAM,EAAO,CAAI,EAC7B,EAAI,EAAE,CAAC,KAAK,CAAI,EAEhB,EAAI,EAAE,CAAC,KAAK,CAAI,EAGpB,OAAO,CACT"}