Skip to content

Macil/map-indexed-xf

Repository files navigation

map-indexed-xf

GitHub license npm version CircleCI Status Greenkeeper badge

This module defines a function that returns a transducer which calls a given function with each value and its index. This transducer may be used with Javascript transducer libraries such as jlongster/transducers.js and cognitect-labs/transducers-js.

Example

const t = require('transducers.js');
const mapIndexed = require('map-indexed-xf');

const result = t.toArray([5,6,7], t.compose(
  t.map(x => x*10),
  mapIndexed((x, i) => [i, x])
));

console.log(result); // [[0, 50], [1, 60], [2, 70]]

Types

TypeScript type definitions for this module are included! The type definitions won't require any configuration to use.