result

.zn module

First-class Result and Option wrappers, for passing errors as values instead of using multi-return. import "result".

Result

Option

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.

On this page