Function: unzip()
unzip<
ElementType>(iterable:IterableResolvable<ElementType>):UnzipIterable<ElementType>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/unzip.ts:28
Creates an array for each element of the input iterable, transposing the input iterable. The opposite of zip.
Type Parameters
| Type Parameter |
|---|
ElementType extends readonly any[] |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | An iterable to unzip. |
Returns
UnzipIterable<ElementType>
An array of iterables that yield the values of the original iterable.
Example
import { unzip } from '@sapphire/iterator-utilities';
const iterable = [[1, 'a'], [2, 'b'], [3, 'c']];
const [numbers, letters] = unzip(iterable);
console.log(numbers);
// Output: [1, 2, 3]
console.log(letters);
// Output: ['a', 'b', 'c']
Remarks
This function consumes the entire iterable.