isMatrix

Returns whether a value is a valid matrix, using the same structure rule as from but without cloning.

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

Matrix.isMatrix({ "2024": [1, 2], "2025": [3] }); // true
Matrix.isMatrix({}); // true (empty matrix)

Matrix.isMatrix(null); // false
Matrix.isMatrix([1, 2]); // false (top-level array)
Matrix.isMatrix({ a: 1 }); // false (row is not an array)
Matrix.isMatrix(new Date()); // false

// Narrow unknown input before using matrix APIs.
const input: unknown = { a: [1] };
if (Matrix.isMatrix(input)) {
  Matrix.sum(input); // 1
}

API Reference

Signature

Matrix.isMatrix(value: unknown): value is Matrix<unknown>;

Parameters

ParameterTypeRequiredNotes
valueunknownYesValue to inspect.

Returns

true for a plain object whose own enumerable string keys all map to dense arrays; false otherwise. Does not clone.

Throws

Does not throw.

Agent Contract

FieldValue
Kindstatic predicate
Canonical nameisMatrix
AliasesNone
Mutates inputsNo
Returnsvalue is Matrix<unknown>

Agent Notes

  • Use isMatrix for control flow; use assertMatrix to throw, or from to validate and clone in one step.
  • Sparse-array rows are rejected, matching from.