@epikodelabs/streamix / expand
Function: expand()
expand<
T>(project,options):Operator<T,T>
Defined in: projects/libraries/streamix/src/lib/operators/expand.ts:44
Creates a stream operator that recursively expands each emitted value.
This operator takes each value from the source stream and applies the project function to it, which must return a new stream. It then recursively applies the same logic to each value emitted by that new stream, effectively flattening an infinitely deep, asynchronous data structure.
This is particularly useful for traversing graph or tree-like data, such as file directories or hierarchical API endpoints, where each item might lead to a new collection of items that also need to be processed.
Type Parameters
T
T = any
The type of the values in the source and output streams.
Parameters
project
(value) => MaybePromise<T | Stream<T> | T[]>
A function that takes a value and returns a stream, value/array, or a promise of those shapes to be expanded.
options
ExpandOptions = {}
An optional configuration object for traversal strategy and max depth.
Returns
Operator<T, T>
An Operator instance that can be used in a stream's pipe method.