API · Transform
flatten()
Emit the members of each synchronous iterable, one level deep.
Signature
flatten(): Exstream<FlatValue<T>, C> Example
exstream([[1, 2], new Set([3, 4]), 5])
.flatten()
.valuesSync()
// [1, 2, 3, 4, 5] Flattening
Arrays, sets, maps, generators, typed arrays, and other values with Symbol.iterator are expanded in iteration order. Strings are deliberately treated as scalar values. Non-iterables pass through unchanged. Flattening is exactly one level; nested iterables remain nested.
exstream([[[1]], 'ab'])
.flatten()
.valuesSync()
// [[1], 'ab'] Pressure and context
flatten() consumes each iterable synchronously. It does not retain a separate collection, but a very large or infinite synchronous iterable can monopolize the current turn and can fill downstream buffers before upstream advances. Use bounded iterables and makeAsync() when yielding is necessary.
Every expanded member receives a fork of the parent record context when one exists; scalar values keep their context. Order is stable.
Errors
Existing record errors pass through. flatten() does not catch exceptions thrown while obtaining or advancing an iterator; such an exception escapes the synchronous delivery call instead of becoming a contextual record error. Wrap fallible iterables before this operator when the pipeline must recover per record.
Forms
stream.flatten()
exstream.pipeline().flatten()
exstream.flatten(stream)