THT is in early Beta. We welcome contributors & feedback.

Result

An implementation of the Option Type pattern.

A Result object cleanly separates the return status (e.g. success/fail) from the return value.

This approach is less error-prone than returning a special value (e.g. -1) to indicate failure.

let result = runProcess();
if (result.ok()) {
    print(result.get());  //= 'Yay!'
} else {
    die('Process failed with code: ' ~ result.failCode());
}

function runProcess() {

    // (do something)

    if (isOk) {
        // Success - a valid return value
        return Result.new('Yay!');
    }
    else {
        // Failure
        return Result.fail(66);
    }
}