Skip to main content

Function: toIterableIterator()

toIterableIterator<ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType>

Creates an iterable iterator from an iterable or iterator-like object.

Type parameters

Type parameter
ElementType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>The iterable or iterable-like object to convert.

Returns

IterableIterator<ElementType>

An iterable iterator.

Example

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

const array = [1, 2, 3, 4, 5];
console.log([...toIterableIterator(array)]);
// Output: [1, 2, 3, 4, 5]

const set = new Set([1, 2, 3, 4, 5]);
console.log([...toIterableIterator(set)]);
// Output: [1, 2, 3, 4, 5]

const map = new Map([['a', 1], ['b', 2], ['c', 3]]);
console.log([...toIterableIterator(map)]);
// Output: [['a', 1], ['b', 2], ['c', 3]]

const string = 'hello';
console.log([...toIterableIterator(string)]);
// Output: ['h', 'e', 'l', 'l', 'o']

Source

projects/utilities/packages/iterator-utilities/src/lib/toIterableIterator.ts:31