Skip to main content
Module

x/aitertools/mod.ts>range

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

Creates a Range of numbers from 0 to stop with step 1.

import { range } from "./range.ts";

for (const value of range(4)) console.log(value);

The above example will print the following 4 lines:

0
1
2
3

Note that the type of the range is Range<number>, which implements both Iterable<number> and AsyncIterable<number>.

Parameters

stop: number

The stop of the range.

Returns

Range<number>

Creates a Range of bigints from 0 to stop with step 1.

import { range } from "./range.ts";

for (const value of range(4n)) console.log(value);

The above example will print the following 4 lines:

0
1
2
3

Note that the type of the range is Range<bigint>, which implements both Iterable<bigint> and AsyncIterable<bigint>.

Parameters

stop: bigint

The stop of the range.

Returns

Range<bigint>

Creates a Range of numbers with step 1.

import { range } from "./range.ts";

for (const value of range(2, 5)) console.log(value);

The above example will print the following 3 lines:

2
3
4

Note that the type of the range is Range<number>, which implements both Iterable<number> and AsyncIterable<number>.

Parameters

start: number

The start of the range.

stop: number

The stop of the range.

Returns

Range<number>

Creates a Range of bigints with step 1.

import { range } from "./range.ts";

for (const value of range(2n, 5n)) console.log(value);

The above example will print the following 3 lines:

2
3
4

Note that the type of the range is Range<bigint>, which implements both Iterable<bigint> and AsyncIterable<bigint>.

Parameters

start: bigint

The start of the range.

stop: bigint

The stop of the range.

Returns

Range<bigint>

Creates a Range of numbers.

import { range } from "./range.ts";

for (const value of range(10, -10, -3.5)) console.log(value);

The above example will print the following 6 lines:

10
6.5
3
-0.5
-4
-7.5

Note that the type of the range is Range<number>, which implements both Iterable<number> and AsyncIterable<number>.

Parameters

start: number

The start of the range. It must be a finite number.

stop: number

The stop of the range. It must be a finite number.

step: number

The step of the range. It must be a finite number, and cannot be zero.

Returns

Range<number>

Creates a Range of bigints.

import { range } from "./range.ts";

for (const value of range(10n, -10n, -5n)) console.log(value);

The above example will print the following 4 lines:

10
5
0
-5

Note that the type of the range is Range<bigint>, which implements both Iterable<bigint> and AsyncIterable<bigint>.

Parameters

start: bigint

The start of the range.

stop: bigint

The stop of the range.

step: bigint

The step of the range. Cannot be zero.

Returns

Range<bigint>

A Range of bigints.