@epikodelabs/streamix / fork
Function: fork()
fork<
T,R>(...options):Operator<T,R>
Defined in: projects/libraries/streamix/src/lib/operators/fork.ts:59
Creates a stream operator that routes each source value through a specific handler based on matching predicates defined in the provided ForkOptions.
For each value from the source stream:
- Iterates over the
optionsarray. - Executes the
onpredicate for each option until one returnstrue. - Calls the corresponding
handlerfor the first matching option. - Flattens the result (stream, value, promise, or array) sequentially into the output stream.
If no predicate matches a value, an error is thrown.
This operator allows conditional branching in streams based on the content of each item.
Type Parameters
T
T = any
The type of values in the source stream.
R
R = any
The type of values emitted by the output stream.
Parameters
options
...ForkOption<T, R>[]
ForkOption objects defining predicates and handlers.
Returns
Operator<T, R>
An Operator instance suitable for use in a stream's pipe method.
Throws
If a source value does not match any predicate.