axax
Version:
A library of async iterator extensions for JavaScript including ```map```, ```reduce```, ```filter```, ```flatMap```, ```pipe``` and [more](https://github.com/jamiemccrindle/axax/blob/master/docs/API.md#functions).
18 lines (17 loc) • 516 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Goes through a iterable applying the scanner function to the accumulator
* returning the accumulator at each step
*/
function scan(scanner, init) {
return async function* inner(source) {
let accumulator = await init;
for await (const next of source) {
yield accumulator;
accumulator = await scanner(accumulator, next);
}
yield accumulator;
};
}
exports.scan = scan;