(n: number): <A>(self: Iterable<A>) => Iterable<A>
<A>(self: Iterable<A>, n: number): Iterable<A>Repeats an iterable n times, yielding the full contents of self for each
repetition.
When to use
Use to repeat an iterable's contents a specific number of times.
Details
The result is lazy. Each repetition obtains a new iterator from self.
export const const repeat: {
(n: number): <A>(
self: Iterable<A>
) => Iterable<A>
<A>(self: Iterable<A>, n: number): Iterable<A>
}
Repeats an iterable n times, yielding the full contents of self for each
repetition.
When to use
Use to repeat an iterable's contents a specific number of times.
Details
The result is lazy. Each repetition obtains a new iterator from self.
repeat: {
(n: numbern: number): <function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>
<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>, n: numbern: number): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>
} = import dualdual(2, <function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>, n: numbern: number): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A> => const flatten: <A>(
self: Iterable<Iterable<A>>
) => Iterable<A>
Flattens an Iterable of Iterables into a single Iterable
Example (Flattening nested iterables)
import { Iterable } from "effect"
// Flatten nested arrays
const nested = [[1, 2], [3, 4], [5, 6]]
const flat = Iterable.flatten(nested)
console.log(Array.from(flat)) // [1, 2, 3, 4, 5, 6]
// Flatten different iterable types
const mixed: Array<Iterable<string>> = ["ab", "cd"]
const flatMixed = Iterable.flatten(mixed)
console.log(Array.from(flatMixed)) // ["a", "b", "c", "d"]
// Flatten deeply nested (only one level)
const deepNested = [[[1, 2]], [[3, 4]]]
const oneLevelFlat = Iterable.flatten(deepNested)
console.log(Array.from(oneLevelFlat).map((arr) => Array.from(arr)))
// [[1, 2], [3, 4]] (still contains arrays)
// Empty iterables are handled correctly
const withEmpty = [[1, 2], [], [3, 4], []]
const flatWithEmpty = Iterable.flatten(withEmpty)
console.log(Array.from(flatWithEmpty)) // [1, 2, 3, 4]
flatten(const makeBy: <Iterable<A>>(f: (i: number) => Iterable<A>, options?: {
readonly length?: number;
}) => Iterable<Iterable<A>>
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(() => self: Iterable<A>self, { length?: number | undefinedlength: n: numbern })))