{"version":3,"file":"arrays.cjs","names":[],"sources":["../../src/utils/arrays.ts"],"sourcesContent":["/**\n * Group items of a list into buckets keyed by the result of `key`.\n *\n * Items preserve their original order within each bucket.\n *\n * @example\n * groupBy([1, 2, 3, 4], (n) => (n % 2 === 0 ? \"even\" : \"odd\"));\n * // { odd: [1, 3], even: [2, 4] }\n *\n * @example\n * groupBy([{ city: \"SP\" }, { city: \"RJ\" }, { city: \"SP\" }], (u) => u.city);\n * // { SP: [{ city: \"SP\" }, { city: \"SP\" }], RJ: [{ city: \"RJ\" }] }\n */\nexport function groupBy<T, K extends PropertyKey>(items: T[], key: (item: T) => K): Record<K, T[]> {\n    const result = {} as Record<K, T[]>;\n    for (const item of items) {\n        const k = key(item);\n        (result[k] ??= []).push(item);\n    }\n    return result;\n}\n\n/**\n * Remove duplicate items, keeping the first occurrence of each distinct key.\n *\n * Equality is determined by the value returned from `key` (compared with `===`).\n *\n * @example\n * uniqueBy([1, 2, 2, 3, 1], (n) => n); // [1, 2, 3]\n *\n * @example\n * uniqueBy(\n *   [{ id: 1, v: \"a\" }, { id: 1, v: \"b\" }, { id: 2, v: \"c\" }],\n *   (u) => u.id,\n * );\n * // [{ id: 1, v: \"a\" }, { id: 2, v: \"c\" }]\n */\nexport function uniqueBy<T>(items: T[], key: (item: T) => unknown): T[] {\n    const seen = new Set<unknown>();\n    const result: T[] = [];\n    for (const item of items) {\n        const k = key(item);\n        if (!seen.has(k)) {\n            seen.add(k);\n            result.push(item);\n        }\n    }\n    return result;\n}\n\n/**\n * Split a list into consecutive chunks of at most `size` items.\n *\n * The final chunk may be smaller than `size`. An empty input yields `[]`.\n *\n * @param items - The list to split.\n * @param size - Maximum chunk length; must be `>= 1`.\n * @throws {RangeError} When `size` is less than `1`.\n *\n * @example\n * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n *\n * @example\n * chunk([], 3); // []\n */\nexport function chunk<T>(items: T[], size: number): T[][] {\n    if (size < 1) {\n        throw new RangeError(`chunk size must be >= 1, received ${size}`);\n    }\n    const result: T[][] = [];\n    for (let i = 0; i < items.length; i += size) {\n        result.push(items.slice(i, i + size));\n    }\n    return result;\n}\n\n/**\n * Build a numeric range from `start` (inclusive) to `end` (exclusive).\n *\n * - `step` defaults to `1` and may be negative for descending ranges.\n * - Returns an empty array when no progress can be made toward `end`\n *   (wrong-direction step, zero step, or `start === end`).\n *\n * @param start - First value of the range.\n * @param end - Exclusive upper (or lower, for negative step) bound.\n * @param step - Increment between values; defaults to `1`.\n *\n * @example\n * range(0, 5);        // [0, 1, 2, 3, 4]\n * range(0, 10, 2);    // [0, 2, 4, 6, 8]\n * range(5, 0, -1);    // [5, 4, 3, 2, 1]\n * range(0, 5, -1);    // [] (wrong direction)\n * range(3, 3);        // []\n */\nexport function range(start: number, end: number, step: number = 1): number[] {\n    const result: number[] = [];\n    if (step === 0) return result;\n    if (step > 0) {\n        for (let i = start; i < end; i += step) result.push(i);\n    } else {\n        for (let i = start; i > end; i += step) result.push(i);\n    }\n    return result;\n}\n"],"mappings":"AAaA,SAAgB,EAAkC,EAAY,EAAqC,CAC/F,IAAM,EAAS,CAAC,EAChB,IAAK,IAAM,KAAQ,EAAO,CACtB,IAAM,EAAI,EAAI,CAAI,GACjB,EAAO,KAAO,CAAC,EAAA,CAAG,KAAK,CAAI,CAChC,CACA,OAAO,CACX,CAiBA,SAAgB,EAAY,EAAY,EAAgC,CACpE,IAAM,EAAO,IAAI,IACX,EAAc,CAAC,EACrB,IAAK,IAAM,KAAQ,EAAO,CACtB,IAAM,EAAI,EAAI,CAAI,EACb,EAAK,IAAI,CAAC,IACX,EAAK,IAAI,CAAC,EACV,EAAO,KAAK,CAAI,EAExB,CACA,OAAO,CACX,CAiBA,SAAgB,EAAS,EAAY,EAAqB,CACtD,GAAI,EAAO,EACP,MAAU,WAAW,qCAAqC,GAAM,EAEpE,IAAM,EAAgB,CAAC,EACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,GAAK,EACnC,EAAO,KAAK,EAAM,MAAM,EAAG,EAAI,CAAI,CAAC,EAExC,OAAO,CACX,CAoBA,SAAgB,EAAM,EAAe,EAAa,EAAe,EAAa,CAC1E,IAAM,EAAmB,CAAC,EAC1B,GAAI,IAAS,EAAG,OAAO,EACvB,GAAI,EAAO,EACP,IAAK,IAAI,EAAI,EAAO,EAAI,EAAK,GAAK,EAAM,EAAO,KAAK,CAAC,OAErD,IAAK,IAAI,EAAI,EAAO,EAAI,EAAK,GAAK,EAAM,EAAO,KAAK,CAAC,EAEzD,OAAO,CACX"}