API reference@evolu/commonArray › zipArray

Call Signature

function zipArray<T>(
  arrays: T,
): readonly [Readonly<ZipArrayResult<T>>, Readonly<ZipArrayResult<T>>];

Defined in: packages/common/src/Array.ts:844

Combines multiple arrays into an array of tuples.

Uses "shortest" mode — stops at the shortest input array. Preserves non-empty type when all input arrays are non-empty. See the TC39 Array.zip proposal for the pattern this follows.

Zipping to the shortest input

import { zipArray, type NonEmptyReadonlyArray } from "@evolu/common";

const pairs = zipArray([
  [1, 2, 3],
  ["a", "b", "c"],
]);
expect(pairs).toEqual([
  [1, "a"],
  [2, "b"],
  [3, "c"],
]);
expect(
  zipArray([
    [1, 2],
    ["a", "b", "c"],
    [true, false],
  ]),
).toEqual([
  [1, "a", true],
  [2, "b", false],
]);
expectTypeOf(pairs).toEqualTypeOf<
  NonEmptyReadonlyArray<Readonly<[number, string]>>
>();

Call Signature

function zipArray<T>(arrays: T): readonly Readonly<ZipArrayResult<T>>[];

Defined in: packages/common/src/Array.ts:848

Possibly empty arrays.