Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/fathym_common/src/common/iterables/convertAsyncIterable.ts>convertAsyncIterable

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Latest
function convertAsyncIterable
import { convertAsyncIterable } from "https://deno.land/x/fathym_common@v0.2.160/src/common/iterables/convertAsyncIterable.ts";

Convert an async iterable to an async iterable of another type.

Examples

From direct import

import { convertAsyncIterable } from '@fathym/common/iterables';

const asyncIterable = {
 [Symbol.asyncIterator]() {
   let i = 0;

   return {
     next() {
       if (i < 3) {
         return Promise.resolve(i);
       }

       return Promise.resolve(i);
     };
   }
 }
};

const ai = await convertAsyncIterable(asyncIterable, async (i) => i * 2);

console.log(Array.from(ai)); // [0, 2, 4, 6]

From common import

import { convertAsyncIterable } from '@fathym/common';

const ai = await convertAsyncIterable(asyncIterable, async (i) => i * 2);

console.log(Array.from(ai)); // [0, 2, 4, 6]

Parameters

source: AsyncIterable<T>

The incoming iterable to convert

converter: (item: T) => Promise<R>

The method to use for converting the item.

Returns

AsyncIterable<R>

The async iterable of converted items.