fromEntries

Builds a matrix from sparse entries, placing each value at its index.

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

Matrix.fromEntries([
  { key: "a", index: 0, value: 1 },
  { key: "a", index: 2, value: 3 },
]);
// { a: [1, undefined, 3] }  (gaps are undefined; row length = max index + 1)

// Keys are emitted ascending.
Matrix.fromEntries([
  { key: "b", index: 0, value: 1 },
  { key: "a", index: 0, value: 2 },
]);
// { a: [2], b: [1] }

// A later key+index overwrites an earlier one.
Matrix.fromEntries([
  { key: "a", index: 0, value: 1 },
  { key: "a", index: 0, value: 9 },
]);
// { a: [9] }

Matrix.fromEntries([{ key: "a", index: -1, value: 1 }]); // throws "MATRIX_INVALID_ENTRY"

API Reference

Signature

Matrix.fromEntries<T, TKey extends string>(
  entries: readonly MatrixEntryInput<T, TKey>[],
): Matrix<T | undefined, TKey>;
// MatrixEntryInput: { key, index, value }

Parameters

ParameterTypeRequiredNotes
entriesreadonly { key, index, value }[]Yesindex must be a finite non-negative integer.

Returns

A matrix with keys ascending; each row length is the largest index + 1 for that key, with gaps filled by undefined (never "-").

Throws

  • MATRIX_INVALID_ENTRY — a malformed entry, or an index that is not a finite non-negative integer.

Agent Contract

FieldValue
Kindstatic constructor
Canonical namefromEntries
AliasesNone
Mutates inputsNo
ReturnsMatrix<T | undefined, TKey>

Agent Notes

  • Gaps become undefined, not "-"fromEntries has no period semantics.
  • It consumes MatrixEntryInput (index); the inverse entries produces MatrixEntry (colIndex).