zip

Zips several matrices, combining same-position values into tuples, over the union of their keys.

import { Matrix } from "@teakit/matrix";

Matrix.zip([{ a: [1, 2] }, { a: [10] }]);
// { a: [[1, 10], [2, undefined]] }  (missing -> undefined)

Matrix.zip([{ a: [1] }, { b: [2] }]);
// { a: [[1, undefined]], b: [[undefined, 2]] }  (union keys, ascending)

// "-" is kept in the tuple, not skipped.
Matrix.zip([{ a: ["-"] }, { a: [5] }]);
// { a: [["-", 5]] }

API Reference

Signature

Matrix.zip<TMatrices extends readonly [Matrix, ...Matrix[]]>(
  matrices: TMatrices,
): Matrix<MatrixZipValues<TMatrices>, MatrixUnionKeys<TMatrices>>;

Parameters

ParameterTypeRequiredNotes
matrices[Matrix, ...Matrix[]]YesNon-empty array.

Returns

A matrix keyed by the union of input keys (ascending), each cell a tuple with one value per input matrix. Each key's row length is the max across inputs; a matrix missing a key or column contributes undefined.

Throws

  • MATRIX_INVALID_ZIP_INPUT — non-array / empty matrices.

Agent Contract

FieldValue
Kindstatic combinator
Canonical namezip
AliasesNone
Mutates inputsNo
ReturnsMatrix<MatrixZipValues<TMatrices>, MatrixUnionKeys<TMatrices>>

Agent Notes

  • zip is merge with an identity tuple resolver; use merge when you need to reduce the values instead.
  • A present "-" stays in the tuple; only a missing key/column is undefined.