Skip to main content

range

range() function

Returns Iterable/AsyncIterable of numbers (positive and/or negative) progressing from start-up to, but not including, end. it's set to start with a start then set to 0.

Signature:
declare function range(length: number): IterableIterator<number>;

declare function range(start: number, end: number): IterableIterator<number>;

declare function range(start: number, end: number, step: number): IterableIterator<number>;

Example

const iter = range(4);
iter.next() // {done:false, value: 0}
iter.next() // {done:false, value: 1}
iter.next() // {done:false, value: 2}
iter.next() // {done:false, value: 3}
iter.next() // {done:true, value: undefined}

// with pipe
pipe(
range(4),
toArray,
); // [0, 1, 2, 3]

pipe(
range(1, 4),
toArray,
); // [1, 2, 3]

// with toAsync
await pipe(
range(4),
toAsync,
toArray,
); // [0, 1, 2, 3]

Try It

see pipe, toAsync, toArray