is-narrowing
is checks whether a value matches a pattern and, where it does, narrows the type
accordingly. Inside the if r is Ok(n) branch, n is the Int payload of the
Ok — already extracted, with no separate unwrap step and no way to reach for a
value that is not there.
It is the lightweight counterpart to match: useful when you care about one shape
and have a sensible fallback for the rest. Choose Edit & run in-page below (or open it in the playground) to see how n
is in scope only where it is known to exist, and press Run to see both branches
taken.
context demo
---`is` tests a value against a pattern and narrows it. Inside the `if`, `n` is an`Int` — the `Ok` payload — without an explicit unwrap.---fn useValue(r: Result[Int, String]) -> Int { if r is Ok(n) { n } else { 0 }}
---Run calls `service playground`: one `Ok` and one `Err`, so you see both branches.---service playground { on call() -> Effect[List[Int]] by Caller { [useValue(Ok(7)), useValue(Err("missing"))] }}