(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])export const const range: (
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])
range = (start: numberstart: number, end: number | undefinedend?: number): interface Iterable<T, TReturn = any, TNext = any>Iterable<number> => {
if (end: number | undefinedend === var undefinedundefined) {
return const makeBy: <number>(
f: (i: number) => number,
options?: {
readonly length?: number
}
) => Iterable<number>
Creates an iterable by applying a function to consecutive integers.
Details
The function is called with each index starting from 0. If no length is
specified, the iterable is infinite. This is useful for generating
sequences, patterns, or any indexed data.
Example (Generating values by index)
import { Iterable } from "effect"
// Generate first 5 even numbers
const evens = Iterable.makeBy((n) => n * 2, { length: 5 })
console.log(Array.from(evens)) // [0, 2, 4, 6, 8]
// Generate squares
const squares = Iterable.makeBy((n) => n * n, { length: 4 })
console.log(Array.from(squares)) // [0, 1, 4, 9]
// Infinite sequence (be careful when consuming!)
const naturals = Iterable.makeBy((n) => n)
const first10 = Iterable.take(naturals, 10)
console.log(Array.from(first10)) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
makeBy((i: numberi) => start: numberstart + i: numberi)
}
return const makeBy: <number>(
f: (i: number) => number,
options?: {
readonly length?: number
}
) => Iterable<number>
Creates an iterable by applying a function to consecutive integers.
Details
The function is called with each index starting from 0. If no length is
specified, the iterable is infinite. This is useful for generating
sequences, patterns, or any indexed data.
Example (Generating values by index)
import { Iterable } from "effect"
// Generate first 5 even numbers
const evens = Iterable.makeBy((n) => n * 2, { length: 5 })
console.log(Array.from(evens)) // [0, 2, 4, 6, 8]
// Generate squares
const squares = Iterable.makeBy((n) => n * n, { length: 4 })
console.log(Array.from(squares)) // [0, 1, 4, 9]
// Infinite sequence (be careful when consuming!)
const naturals = Iterable.makeBy((n) => n)
const first10 = Iterable.take(naturals, 10)
console.log(Array.from(first10)) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
makeBy((i: numberi) => start: numberstart + i: numberi, {
length?: number | undefinedlength: start: numberstart <= end: numberend ? end: numberend - start: numberstart + 1 : 1
})
}