Hyperlinkv0.8.0-beta.28

Iterable

Iterable.rangeconsteffect/Iterable.ts:95
(start: number, end?: number): Iterable<number>

Returns an iterable of integers starting at start and increasing by 1.

Details

When end is provided and start <= end, both endpoints are included. When end is omitted, the iterable is unbounded. When start > end, the iterable contains only start.

Example (Creating a range)

import { Iterable } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(Array.from(Iterable.range(1, 3)), [1, 2, 3])
constructors
Source effect/Iterable.ts:958 lines
export const range = (start: number, end?: number): Iterable<number> => {
  if (end === undefined) {
    return makeBy((i) => start + i)
  }
  return makeBy((i) => start + i, {
    length: start <= end ? end - start + 1 : 1
  })
}