1 | import { AsyncIterableX } from '../asynciterable';
|
2 | import { bindCallback } from '../util/bindcallback';
|
3 | class MapAsyncIterable extends AsyncIterableX {
|
4 | constructor(source, selector) {
|
5 | super();
|
6 | this._source = source;
|
7 | this._selector = selector;
|
8 | }
|
9 | async *[Symbol.asyncIterator]() {
|
10 | let i = 0;
|
11 | for await (const item of this._source) {
|
12 | yield await this._selector(item, i++);
|
13 | }
|
14 | }
|
15 | }
|
16 | export function mapAsync(source, selector, thisArg) {
|
17 | return new MapAsyncIterable(source, bindCallback(selector, thisArg, 2));
|
18 | }
|
19 |
|
20 |
|