# Fx.when

Conditionally emits one of two values based on the boolean value emitted by the condition stream.

## Signatures

```ts
export declare const when: <E, R, B, C>(condition: Fx<boolean, E, R>, matchers: {
    onTrue: B;
    onFalse: C;
}) => Fx<B | C, E, R | Scope>;
```

## Why

`when` is the value-only form of `if`, implemented with `switchMap`. Each condition push selects a
constant inner Fx, but a newer condition can interrupt that inner before it emits; output
cardinality can therefore be lower than the number of condition values.

## Ownership and lifetime

It delegates branch switching to `if`; its constant branches acquire no resources. The Scope owns
scheduled branch fibers, replacement awaits their interruption, and source completion waits for
the latest selected branch.

## Examples

```ts
import { Fx } from "@typed/fx"
const program = Fx.collectAll(
  Fx.when(Fx.fromIterable([true, false]), { onTrue: "yes", onFalse: "no" })
) // the later `false` may replace `true` before "yes" is emitted
```
