Skip to content

repeat() function

指定された値を含むサイズ n の Iterable/AsyncIterable を返します。

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.