Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Blocks

Example: scope

func scope<T>(body: block() -> T) -> T {
    body!()
}

Example: Option<T>

condition
    .then { print("was true") }
    .else { print("was false") }
func then<T>(self: Boolean, body: block() -> T) -> Option<T> {
    match(self) {
        True -> Some(body!()),
        False -> None,
    }
}

func else<T>(self: Option<T>, body: block() -> T) -> T {
    match(self) {
        Some(value) -> value,
        None -> body!(),
    }
}

Example: while

let mut i = 1;

while { i < 6 } {
    print(i);
    i = i + 1;
}
func while(condition: block() -> Boolean, body: block()) {
    loop {
        condition!().then {
            body!();
        };
    };
}