@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
23 lines • 467 B
JavaScript
import { map } from './map.js';
/**
* Adds a counter representing the amount of chunks
* received thus far.
*
* @group Transformers
* @example
* ```
* --a----------------------b-------|
*
* withCounter()
*
* --{chunk:'a',counter:0}--{chunk:'b',counter:1}-|
* ```
*/
export function withCounter(start = 0) {
let counter = start;
return map((chunk) => ({
chunk,
counter: counter++,
}));
}
//# sourceMappingURL=withCounter.js.map