Skip to main content
Module

x/aitertools/concat.ts>concat

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

Concatenates multiple async iterables into one async iterable.

import { concat } from "./concat.ts";

async function* gen() { yield "foo"; yield "bar"; yield "baz"; yield "qux" }
const iterable = concat(gen(), ["a", "b", "c", "d"]);
for await (const value of iterable) console.log(value);

The above example will print the following 8 lines:

foo
bar
baz
qux
a
b
c
d

Type Parameters

T

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

Parameters

...sources: (AsyncIterable<T> | Iterable<T>)[]

Async iterables to concatenate. It can be either finite or infinite, and finite iterables and infinite iterables can be mixed.

Returns

AsyncIterableIterator<T>

An async iterable that contains elements from the iterable sources. If any of the iterable sources is infinite, the returned iterable is infinite.