<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]sequencing
Source effect/Iterable.ts:158922 lines
export const 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 = <function (type parameter) A in <A>(self: Iterable<Iterable<A>>): Iterable<A>A>(self: Iterable<Iterable<A>>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<Iterable<A>>): Iterable<A>A>>): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<Iterable<A>>): Iterable<A>A> => ({
[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]() {
const const outerIterator: Iterator<
Iterable<A>,
any,
any
>
outerIterator = self: Iterable<Iterable<A>>self[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
let let innerIterator:
| Iterator<A, any, any>
| undefined
innerIterator: interface Iterator<T, TReturn = any, TNext = any>Iterator<function (type parameter) A in <A>(self: Iterable<Iterable<A>>): Iterable<A>A> | undefined
function function (local function) next(): IteratorReturnResult<any> | IteratorYieldResult<A>next() {
if (let innerIterator:
| Iterator<A, any, any>
| undefined
innerIterator === var undefinedundefined) {
const const next: IteratorResult<
Iterable<A>,
any
>
next = const outerIterator: Iterator<
Iterable<A>,
any,
any
>
outerIterator.Iterator<Iterable<A>, any, any>.next(...[value]: [] | [any]): IteratorResult<Iterable<A>, any>next()
if (const next: IteratorResult<
Iterable<A>,
any
>
next.done?: boolean | undefineddone) {
return const next: IteratorReturnResult<any>next
}
let innerIterator:
| Iterator<A, any, any>
| undefined
innerIterator = const next: IteratorYieldResult<
Iterable<A>
>
next.IteratorYieldResult<Iterable<A>>.value: Iterable<A>value[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
}
const const result: IteratorResult<A, any>result = let innerIterator: Iterator<A, any, any>innerIterator.Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next()
if (const result: IteratorResult<A, any>result.done?: boolean | undefineddone) {
let innerIterator:
| Iterator<A, any, any>
| undefined
innerIterator = var undefinedundefined
return function (local function) next(): IteratorReturnResult<any> | IteratorYieldResult<A>next()
}
return const result: IteratorYieldResult<A>result
}
return { Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next }
}
})Referenced by 2 symbols