/** * Just some basic utilities for async generators that should really be part of the language or lodash or something. */ export async function* asyncFilter(it: AsyncIterableIterator, pred: (x: T) => boolean): AsyncIterableIterator { for await (const x of it) { if (pred(x)) { yield x; } } } export async function* asyncMap(it: AsyncIterableIterator, mapper: (x: T) => R): AsyncIterableIterator { for await (const x of it) { yield mapper(x); } } export async function toArray(it: AsyncIterableIterator): Promise { const result = []; for await (const x of it) { result.push(x); } return result; }