UNPKG

typedash

Version:

modern, type-safe collection of utility functions

1 lines 1.61 kB
{"version":3,"file":"zip-CpA3kYsf.cjs","names":[],"sources":["../src/functions/zip/zip.ts"],"sourcesContent":["import type { TypedArray } from 'type-fest';\n\n/**\n * Zips two arrays together into an array of tuples.\n * @param first The first array to zip.\n * @param second The second array to zip.\n * @returns An array of tuples containing the zipped values.\n */\nexport function zip<T, U>(first: readonly T[], second: readonly U[]): [T, U][];\n/**\n * Zips two typed arrays together into an array of tuples.\n * @param first The first array to zip.\n * @param second The second array to zip.\n * @returns An array of tuples containing the zipped values.\n */\nexport function zip<T extends TypedArray, U extends TypedArray>(\n first: T,\n second: U\n): [T[number], U[number]][];\n/**\n * Implementation for all overloads.\n * @param first The first array to zip.\n * @param second The second array to zip.\n * @returns An array of tuples containing the zipped values.\n */\nexport function zip<\n T extends readonly unknown[] | TypedArray,\n U extends readonly unknown[] | TypedArray,\n>(first: T, second: U) {\n const result: [T[number], U[number]][] = [];\n\n for (let index = 0; index < Math.min(first.length, second.length); index++) {\n // biome-ignore lint/style/noNonNullAssertion: we're getting the min length first\n result.push([first[index]!, second[index]!]);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;AAyBA,SAAgB,IAGd,OAAU,QAAW;CACrB,MAAM,SAAmC,EAAE;AAE3C,MAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,IAAI,MAAM,QAAQ,OAAO,OAAO,EAAE,QAEjE,QAAO,KAAK,CAAC,MAAM,QAAS,OAAO,OAAQ,CAAC;AAG9C,QAAO"}