Version: v0.6.0 - Beta.  We welcome contributors & feedback.  THanks!

Result

An implementation of the Option Type pattern.

Returning a Result object lets you cleanly separate the return status of a function (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.

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

function runProcess() {

    // (do something that could succeed or fail)

    if $isOk {
        return Result.new($correctData);
    }
    else {
        return Result.fail();
    }
}

Methods