Std.Result
Computations that can succeed (Ok) or fail (Err) with a typed error.
Types
Result
type Result a b =
| Ok a
| Err bA value that is either a success (Ok) or a failure (Err).
Functions
is_ok
fun is_ok : Result a b -> BoolReturns True if the value is Ok.
is_err
fun is_err : Result a b -> BoolReturns True if the value is Err.
map
fun map : (f: a -> c) -> (r: Result a b) -> Result c bApplies a function to the Ok value, leaving Err unchanged.
map_err
fun map_err : (f: b -> c) -> (r: Result a b) -> Result a cApplies a function to the Err value, leaving Ok unchanged.
unwrap
fun unwrap : (r: Result a b) -> a where {b: Debug}Returns the Ok value. Panics on Err.
unwrap_or
fun unwrap_or : (default: a) -> (r: Result a b) -> aReturns the Ok value or a default if Err.
and_then
fun and_then : (f: a -> Result c b) -> (r: Result a b) -> Result c bChains a function that returns Result. Short-circuits on Err.
or_else
fun or_else : (fallback: Result a b) -> (r: Result a b) -> Result a bReturns the first Ok value, or tries the fallback on Err.
to_maybe
fun to_maybe : Result a b -> Maybe aConverts a Result to a Maybe, discarding the error.
from_maybe
fun from_maybe : (err: e) -> (m: Maybe a) -> Result a eConverts a Maybe to a Result, using the given error if Nothing.
flatten
fun flatten : Result (Result a b) b -> Result a bFlattens a nested Result.