result
.zn moduleFirst-class Result and Option wrappers, for passing errors as values instead of using multi-return. import "result".
Result
result.ok(value: any) => Resultresult.err(message: string) => Resultresult.is_ok(r) => bool / result.is_err(r) => boolresult.unwrap(r) => anyresult.unwrap_or(r, default_val) => anyresult.error_msg(r) => stringresult.map_result(r, f: (any) => any) => Resultresult.and_then(r, f: (any) => Result) => Result
Option
result.some(value) => Option / result.none() => Optionresult.is_some(o) => bool / result.is_none(o) => boolresult.option_unwrap(o) => any / result.option_unwrap_or(o, default_val) => anyresult.map_option(o, f) => Optionresult.option_and_then(o, f: (any) => Option) => Optionresult.option_ok_or(o, msg: string) => Result
result.ok(value: any) => Result
Success carrying value.
result.err(message: string) => Result
Failure carrying message.
result.is_ok(r) => bool / result.is_err(r) => bool
State check.
result.unwrap(r) => any
The value (returns 0 on an error result — check is_ok first).
result.unwrap_or(r, default_val) => any
Value, or default_val on error.
result.error_msg(r) => string
The error message.
result.map_result(r, f: (any) => any) => Result
Map the ok value.
result.and_then(r, f: (any) => Result) => Result
Monadic chain.
result.some(value) => Option / result.none() => Option
Present / absent.
result.is_some(o) => bool / result.is_none(o) => bool
State check.
result.option_unwrap(o) => any / result.option_unwrap_or(o, default_val) => any
Extract the value.
result.map_option(o, f) => Option
Map the some value.
result.option_and_then(o, f: (any) => Option) => Option
Monadic chain.
result.option_ok_or(o, msg: string) => Result
Option → Result.