map

Maps every cell into a new sheet, visiting and emitting keys in ascending order.

import { Sheet } from "@teakit/sheet";

Sheet.map({ b: [1, 2], a: [3] }, (value) => value * 2);
// { a: [6], b: [2, 4] }  (keys ascending)

// The context exposes key, rowIndex (in ascending key order), and colIndex.
Sheet.map({ b: [1, 2], a: [3] }, (_value, ctx) => ctx.rowIndex);
// { a: [0], b: [1, 1] }

Sheet.map({ b: [1, 2], a: [3] }, (_value, ctx) => ctx.colIndex);
// { a: [0], b: [0, 1] }

API Reference

Signature

Sheet.map<T, U, TKey extends string>(
  sheet: Sheet<T, TKey>,
  mapper: SheetMapper<T, U, TKey>,
): Sheet<U, TKey>;
// SheetMapper: (value, { key, rowIndex, colIndex }) => U

Parameters

ParameterTypeRequiredNotes
sheetSheet<T, TKey>YesSource sheet.
mapper(value, context) => UYescontext is { key, rowIndex, colIndex }.

Returns

A new sheet with the same keys (ascending) and mapped values. The input is not mutated.

Throws

Does not throw (beyond errors raised by mapper).

Agent Contract

FieldValue
Kindstatic traversal
Canonical namemap
AliasesNone (no mapSheet)
Mutates inputsNo
ReturnsSheet<U, TKey>

Agent Notes

  • rowIndex follows ascending key order, not object insertion order.
  • For folding to a single value use reduce; for a flat list use entries.