function range
range(options: RangeToOptions | RangeUntilOptions): Enumerable<number>

Lazily generate a range of numbers as an AsyncIterable.

Two forms available:

  • to: Exclusive upper bound
  • until: Inclusive upper bound

Supports negative steps for counting down.

Examples

Exclusive range (to)

import { range } from "jsr:@j50n/proc";

const result = await range({ to: 3 }).collect();
// [0, 1, 2]

Inclusive range (until)

import { range } from "jsr:@j50n/proc";

const result = await range({ from: 1, until: 3 }).collect();
// [1, 2, 3]

Negative step

import { range } from "jsr:@j50n/proc";

const result = await range({ from: -1, until: -3, step: -1 }).collect();
// [-1, -2, -3]

Parameters

Range configuration.

Return Type

Enumerable<number>

An Enumerable of numbers.

See