Skip to main content

Function: repeat()

repeat<ElementType>(value: ElementType, count: number): IterableIterator<ElementType>

Creates an iterable that repeats the input iterable count times.

Type parameters

Type parameter
ElementType

Parameters

ParameterTypeDescription
valueElementTypeThe value to be repeated.
countnumberThe number of times to repeat the value.

Returns

IterableIterator<ElementType>

Example

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

const iterator = repeat('Hello, world!', 3);
console.log([...iterator]);
// Output: ['Hello, world!', 'Hello, world!', 'Hello, world!']

Remarks

This function does not clone value, it will be repeated as a reference.

Source

projects/utilities/packages/iterator-utilities/src/lib/repeat.ts:22