API Reference › Builtin functions › unwrap_or
function

unwrap_or

unwrap_or(o: option, fallback) -> int

Reads an option: returns its value when it is some, or fallback when it is none. The safe, one-line way to get a usable value out of an option without a separate branch.

Parameters

othe option to read
fallbackthe value to use when the option is empty

Example

program Config {
  handler Step phase Update {
    let volume = unwrap_or(none(), 100)     # default to 100
  }
}
← All symbols