Skip to main content
Deno 2 is finally 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.
Go to Latest
function convertAsyncIterable
import { convertAsyncIterable } from "https://deno.land/x/fathym_common@v0.2.22-integration/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.