Skip to main content

chain()

chain<T>(source): Chain<T>

Defined in: src/Chain.ts:244

Wraps an iterable in a chain, on which operators can be applied one after another with methods such as map, filter, batch or pipe.

The chain is itself an AsyncIterable; finish it with toArray() or consume(), or iterate it with for await.

Type Parameters​

T​

T

Parameters​

source​

Iter<T>

any Iter: an array, a generator, an async generator, ...

Returns​

Chain<T>

a chain over the source

Example​

const result = await chain(range(1, 6))
.map((n) => n * 2)
.skip(1)
.take(3)
.toArray();
// => [4, 6, 8]