Skip to main content

Function: repeat()

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

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

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.