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).
19 lines (18 loc) • 524 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Go through the elements of an iterable and return zero or more of them using
* an async iterable.
*
* @param mapper the mapper function to run over the async iterable
*/
function flatMap(mapper) {
return async function* inner(source) {
for await (const item of source) {
for await (const nestedItem of mapper(item)) {
yield nestedItem;
}
}
};
}
exports.flatMap = flatMap;