API Reference › Builtin functions › some
function

some

some(v) -> option

Wraps a present value in an option — the value type that models maybe a value without a magic -1 sentinel. An option is either some(value) (this) or none (empty); test it with is_some / is_none and read it with unwrap_or. The payload is any i32-width scalar — int, fixed, bool, or entity.

Parameters

vthe present value

Example

program Targeting {
  function nearest(count: int) -> option {
    if count == 0 { return none() }
    return some(count - 1)          # the nearest target index
  }
  test "some carries the value" {
    let t = unwrap_or(nearest(3), 0 - 1)
    expect_eq(t, 2)
  }
}
← All symbols