UNPKG

674 BJavaScriptView Raw
1import { AsyncIterableX } from '../asynciterable';
2import { bindCallback } from '../util/bindcallback';
3class FilterIterable extends AsyncIterableX {
4 constructor(source, predicate) {
5 super();
6 this._source = source;
7 this._predicate = predicate;
8 }
9 async *[Symbol.asyncIterator]() {
10 let i = 0;
11 for await (const item of this._source) {
12 if (await this._predicate(item, i++)) {
13 yield item;
14 }
15 }
16 }
17}
18export function filterAsync(source, predicate, thisArg) {
19 return new FilterIterable(source, bindCallback(predicate, thisArg, 2));
20}
21
22//# sourceMappingURL=filterasync.mjs.map