LEARN VOID / DATA & BEHAVIOR

Nullable values

Represent absence explicitly.

Complete program for the synchronous entry adapter. The result below is the returned integer.

nullable.voidDownload source
func double(number: i32) -> i32:
    return number * 2

func entry(number: i32) -> i32:
    var adjustment: (func(i32) -> i32)?
    if number > 0:
        adjustment = double
    return match adjustment:
        Ok(var calculate): calculate(number)
        null: number
Input 5Expected result 10

Represent an optional operation

(func(i32) -> i32)? is a nullable function value. Parentheses distinguish an optional callback from a function with a nullable result. An uninitialized nullable binding starts as null.

Choose whether to assign it

For a positive input, the program assigns double as the adjustment. Zero and negative inputs leave it absent. This models an optional calculation without a separate Boolean flag.

Match before calling

Ok(var calculate) captures a present, nonnullable callback. Input 5 becomes 10; absent adjustment returns the original number, so -3 stays -3. Here Ok matches nullable presence and does not convert the value into a result. Calling a null callback would fail at runtime.