import { Range } from "https://deno.land/x/aitertools@0.6.0/src/range.ts";
An immutable sequence of numbers. It implements both Iterable
and
AsyncIterable
.
It is similar to Python's range()
function.
Properties
The length of the range. Note that it guarantees to return the same value
as Array.from(range).length
.
import { range } from "./range.ts";
console.log(range(10, -10, -3.5).length);
The above example will print 6
.
The start of the range. It must be a finite number.
The step of the range. It must be a finite number, and cannot be zero.
The stop of the range. It must be a finite number.
Methods
Returns the element at the specified index in the range. Note that it
guarantees to return the same value as Array.from(range).at(index)
.
import { range } from "./range.ts";
const r = range(10, -10, -3.5);
console.log(r.at(3), r.at(-1));
The above example will print the following 2 lines:
-0.5
-7.5
Represents the range as a string.
Iterates over the elements of the range, in an asynchronous manner.
import { range } from "./range.ts";
for await (const value of range(4)) console.log(value);
The above example will print the following 4 lines:
0
1
2
3
Iterates over the elements of the range.
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