result
Generated by tinox doc
Result<T> — a success-or-error-string wrapper (like Rust's Result) for functions that can fail without throwing: ok/err construction, isOk/isErr/unwrap/unwrapOr, plus map/andThen/mapErr for chaining without unwrapping early.
Ok and err
import tinox.core.result;
class Main
{
fnc divide(a: Int64, b: Int64) -> Result<Int64>
{
if b == 0
{
return Result<Int64>::err("division by zero");
}
return Result<Int64>::ok(a / b);
}
fnc main() -> Int32
{
let good: Result<Int64> = Main::divide(10, 2);
if good.isOk()
{
println("10 / 2 = " + good.unwrap().toString());
}
let bad: Result<Int64> = Main::divide(10, 0);
if bad.isErr()
{
println("error: " + bad.getError());
}
println("fallback: " + bad.unwrapOr(-1).toString());
return 0;
}
}