Skip to main content
Home

Built and signed on GitHub Actions

Well-tested utility functions dealing with async iterables

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
2 years ago (0.6.0)
function repeat
repeat<T>(
value: T,
times?,
): AsyncIterableIterator<T>

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

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

Parameters

value: T

The value to repeat.

optional
times = Infinity

The number of times to repeat. Defaults to Infinity.

Return Type

AsyncIterableIterator<T>

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

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hongminhee/aitertools

Import symbol

import { repeat } from "@hongminhee/aitertools/infinite";
or

Import directly with a jsr specifier

import { repeat } from "jsr:@hongminhee/aitertools/infinite";

Add Package

pnpm i jsr:@hongminhee/aitertools
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hongminhee/aitertools

Import symbol

import { repeat } from "@hongminhee/aitertools/infinite";

Add Package

yarn add jsr:@hongminhee/aitertools
or (using Yarn 4.8 or older)
yarn dlx jsr add @hongminhee/aitertools

Import symbol

import { repeat } from "@hongminhee/aitertools/infinite";

Add Package

vlt install jsr:@hongminhee/aitertools

Import symbol

import { repeat } from "@hongminhee/aitertools/infinite";

Add Package

npx jsr add @hongminhee/aitertools

Import symbol

import { repeat } from "@hongminhee/aitertools/infinite";

Add Package

bunx jsr add @hongminhee/aitertools

Import symbol

import { repeat } from "@hongminhee/aitertools/infinite";