UNPKG

@thi.ng/transducers

Version:

Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations

14 lines (13 loc) 316 B
import { compR } from "./compr.js"; import { __iter } from "./iterator.js"; function mapIndexed(...args) { return __iter(mapIndexed, args) || ((rfn) => { const r = rfn[2]; const fn = args[0]; let i = args[1] || 0; return compR(rfn, (acc, x) => r(acc, fn(i++, x))); }); } export { mapIndexed };