Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/proc/tools/deps/proc.ts>range

A better way to work with processes in Deno.
Go to Latest
function range
import { range } from "https://deno.land/x/proc@0.21.9/tools/deps/proc.ts";

Lazily create a range of numbers.

There are two forms:

  • from/to/step: to is exclusive, and
  • from/until/step: until is inclusive.

Examples

to is exclusive:

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

until is inclusive. from starts at 0 by default.

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

step can be negative. Default is 1.

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