Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / 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

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

Stream<T> | MaybePromise<T>

falseStream

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

Stream<T> | MaybePromise<T>

Returns

Stream<T>

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

Released under the MIT License.