Skip to main content

Function: flat()

flat<ElementType>(iterables: IterableResolvable <IterableResolvable<ElementType>>): IterableIterator<ElementType>

Creates an iterable that yields the elements of each iterable in the input iterable.

Type parameters

Type parameter
ElementType

Parameters

ParameterTypeDescription
iterablesIterableResolvable <IterableResolvable<ElementType>>An iterator to map.

Returns

IterableIterator<ElementType>

An iterator that yields the entries of each iterator.

Example

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

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

Source

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