API Reference › Builtin functions › is_ok
function

is_ok

is_ok(r: result) -> bool

Tests a result's tag: true when it was built with ok, false when it was built with err. Use it when you want to branch on success without unwrapping the payload — the payload itself is recovered with try/else. It is the exact negation of is_err.

Parameters

rthe result to test

Example

program Check {
  function find(x: int) -> result {
    if x == 7 { return ok(x) }
    return err("missing")
  }
  test "is_ok classifies without unwrapping" {
    expect(is_ok(find(7)))
    expect(not is_ok(find(3)))
  }
}
← All symbols