Skip to content

repeat() function

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

Signature:

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

Example

ts
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]

Open Source Code

Released under the Apache-2.0 License.