Result and Option
Bynk has no null and no thrown exceptions. A function that can fail returns a
Result, and a value that might be absent is an Option — both are ordinary
values you pass around and inspect. The possibility of failure or emptiness is
visible in the type, not hidden in the control flow.
Because the two cases are encoded in the type, you handle them by matching, and the
compiler will not let you read a value that might not be there. label has to
account for both Some and None before it can produce a String. Choose Edit & run in-page below (or open it in the playground) to confirm the missing case cannot be skipped, and press Run to label
a present value and an absent one.
context demo
---Errors are values: a function that can fail returns `Result`, and a value thatmay be absent is an `Option`. There is no `null` and no thrown exception toforget about.---fn ok(n: Int) -> Result[Int, String] { Ok(n)}
fn empty() -> Option[Int] { None}
---You handle both cases by matching — the compiler will not let you read a valuethat might not be there.---fn label(o: Option[Int]) -> String { match o { Some(n) => "present" None => "absent" }}
---Run calls `service playground`, which labels one present value and one absent one.---service playground { on call() -> Effect[List[String]] by Caller { [label(ok(3).ok()), label(empty())] }}