Skip to main content
Module

x/aitertools/mod.ts>repeat

Well-tested utility functions dealing with async iterables
Go to Latest
function repeat
import { repeat } from "https://deno.land/x/aitertools@0.3.1/mod.ts";

Makes an async iterator that yields the same value over and over again. It will repeat indefinitely unless times is specified.

import { repeat } from "./infinite.ts";

const iterable = repeat("v");
for await (const value of iterable) console.log(value);

The above example will print the following and keep going forever:

v
v
v
(...)

However, if you specify the second parameter times it will repeat that many times:

import { repeat } from "./infinite.ts";

const iterable = repeat("V", 3);
for await (const value of iterable) console.log(value);

The above example will print the following 3 lines:

V
V
V

Type Parameters

T

The type of the value and the elements in the returned async iterable.

Parameters

value: T

The value to repeat.

optional
times = [UNSUPPORTED]

The number of times to repeat. Defaults to Infinity.

Returns

AsyncIterableIterator<T>

An async iterable that repeats the value indefinitely or times times.