@epikodelabs/streamix / src/public-api / iif
Function: iif()
iif<
T>(condition,trueStream,falseStream):Atom<T>
Defined in: projects/libraries/streamix/src/lib/factories/iif.ts:17
Creates an atom that chooses between two streams based on a condition.
The condition is evaluated lazily when the atom is subscribed to. This allows for dynamic stream selection based on runtime state.
Type Parameters
T
T = any
The type of the values in the streams.
Parameters
condition
() => MaybePromise<boolean>
A function that returns a boolean to determine which stream to use. It is called when the iif atom is subscribed to.
trueStream
PipeInput<T>
The source to use if the condition is true.
falseStream
PipeInput<T>
The source to use if the condition is false.
Returns
Atom<T>
A new atom that emits values from either trueStream or falseStream based on the condition.