Function: cycle()
cycle<
ElementType
>(iterable
:IterableResolvable
<ElementType
>):IterableIterator
<ElementType
>
Creates an infinite iterable by cycling through the elements of the input iterable.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | An iterator to cycle over. |
Returns
IterableIterator
<ElementType
>
Example
import { cycle } from '@sapphire/iterator-utilities';
const iterable = cycle([1, 2, 3]);
for (const element of iterable) {
console.log(element);
// Output: 1, 2, 3, 1, 2, 3, 1, 2, 3, ...
}
Defined in
projects/utilities/packages/iterator-utilities/src/lib/cycle.ts:20