toAsync() function
AsyncIterable を返します。toAsyncは Iterable 内の Promise 値を処理したい場合に使用します。
Signature:
typescript
declare function toAsync<T>(
iter: Iterable<T | Promise<T>>,
): AsyncIterableIterator<T>;Example
ts
let acc = 0;
for await (const item of toAsync([1, 2, 3, 4, 5])) {
acc += item;
}
// acc: 15
// with pipe
await pipe(
[Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)],
toAsync,
map((a) => a + 10),
toArray, // [11, 12, 13]
);