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.