Skip to main content

repeat

repeat() function

Returns a Iterable/AsyncIterable of size n containing a specified value.

Signature:
declare function repeat<T>(n: number, value: T): IterableIterator<T>;

declare function repeat<T>(n: number): (value: T) => IterableIterator<T>;

Example

const iter = repeat(2, 10);
iter.next(); // {value: 10, done:false}
iter.next(); // {value: 10, done:false}
iter.next(); // {value: undefined, done:true}

// with pipe
pipe(
repeat(2, 10),
toArray,
); // [10, 10]