Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / iif

Function: iif() ​

iif<T>(condition, trueStream, falseStream): Stream<T>

Defined in: projects/libraries/streamix/src/lib/streams/iif.ts:16

Creates a stream that chooses between two streams based on a condition.

The condition is evaluated lazily when the stream 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 stream is subscribed to.

trueStream ​

Stream<T> | Promise<T>

The stream or value to use if the condition is true.

falseStream ​

Stream<T> | Promise<T>

The stream or value to use if the condition is false.

Returns ​

Stream<T>

A new stream that emits values from either trueStream or falseStream based on the condition.

Released under the GNU AGPL v3 or later.