Skip to content

mapWithIndex

mapWithIndex<A, B>(f): (data) => readonly B[]

Defined in: Data/Arr.ts:140

Transforms each element using both its value and its zero-based index.

A

B

(i, a) => B

(data) => readonly B[]

pipe(
  ["a", "b", "c"],
  Arr.mapWithIndex((i, s) => ({ position: i + 1, value: s }))
); // [{ position: 1, value: "a" }, { position: 2, value: "b" }, { position: 3, value: "c" }]