Skip to main content
Module

x/aitertools/mod.ts>fromIterable

Well-tested utility functions dealing with async iterables
Go to Latest
function fromIterable
import { fromIterable } from "https://deno.land/x/aitertools@0.4.0/mod.ts";

Turns a synchrnous iterable source into an async iterable.

import { fromIterable } from "./collections.ts";

function* iterable() { yield 1; yield 2; yield 3; }
const asyncIterable = fromIterable(iterable());
for await (const value of asyncIterable) console.log(value);

The above example will print the following lines:

1
2
3

Type Parameters

T

The type of the elements in the source and the returned async iterable.

Parameters

source: AsyncIterable<T> | Iterable<T>

The synchronous or asynchronous iterable to take elements from. It can be either finite or infinite.

Returns

AsyncIterableIterator<T>

An async iterable that yields the same elements as the source iterable.