@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
31 lines (29 loc) • 1.28 kB
JavaScript
import { AsyncIterableX } from '../asynciterable';
import { bindCallback } from '../util/bindcallback';
class FlatMapAsyncIterable extends AsyncIterableX {
constructor(source, selector) {
super();
this._source = source;
this._selector = selector;
}
async *[Symbol.asyncIterator]() {
for await (const outer of this._source) {
for await (const inner of this._selector(outer)) {
yield inner;
}
}
}
}
/**
* Projects each element of a sequence to a potentially async iterable and flattens the
* resulting sequences into one sequence.
* @param {Iterable<T | Promise<T>> | AsyncIterable<T>} source Source sequence
* @param {function:(value: T): Iterable<R | Promise<R>> | AsyncIterable<R>} selector A transform function to apply to each element.
* @param {Object} [thisArg] An optional "this" binding for the selector function.
* @returns {AsyncIterable<R>} An async iterable whose elements are the result of invoking the one-to-many
* transform function on each element of the input sequence.
*/
export function flatMapAsync(source, selector, thisArg) {
return new FlatMapAsyncIterable(source, bindCallback(selector, thisArg, 1));
}
//# sourceMappingURL=flatmapasync.mjs.map