Skip to main content

Function: chain()

chain<ElementType>(...iterables: IterableResolvable<ElementType>[]): IterableIterator<ElementType>

Similar to append, but takes an iterable of iterables and chains them together.

Type parameters

Type parameter
ElementType

Parameters

ParameterTypeDescription
...iterablesIterableResolvable<ElementType>[]The iterators to chain together.

Returns

IterableIterator<ElementType>

An iterator that yields the values of the provided iterators in order.

Example

import { chain } from '@sapphire/iterator-utilities';

const iterable = chain([1, 2, 3], [4, 5, 6], [7, 8, 9]);
console.log([...iterable]);
// Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

Source

projects/utilities/packages/iterator-utilities/src/lib/chain.ts:19