std.result

Error handling type.

Types

type Result e t = 
    | Err e
    | Ok t

Result represents either success (Ok) or an error (Err)

Values

let unwrap_ok res : forall a e . Result e a -> a

let unwrap_ok_or default res : forall e a . a -> Result e a -> a

let unwrap_err res : forall a e . Result e a -> e

let unwrap_err_or default res : forall a e . e -> Result e a -> e

let map_err f res : forall a f e . (e -> f) -> Result e a -> Result f a

let to_option res : forall a e . Result e a -> Option a

#[implicit]
let eq : forall a e . [Eq e] -> [Eq a] -> Eq (Result e a)

Eq a defines equality (==) on a

#[implicit]
let ord : forall a e . [Ord e] -> [Ord a] -> Ord (Result e a)

Ord a defines an ordering on a

#[implicit]
let functor : forall e . Functor (Result e)

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

#[implicit]
let applicative : forall e . Applicative (Result e)

A Functor with application.

The following laws should hold:

  • wrap id <*> v = v
  • wrap (<<) <*> u <*> v <*> w = u <*> (v <*> w)
  • wrap f <*> wrap x = wrap (f x)
  • u <*> wrap y = wrap (\g -> g x) <*> u

#[implicit]
let monad : forall e . Monad (Result e)

A generalised interface for imperatively sequencing actions

#[implicit]
let foldable : forall e . Foldable (Result e)

Operations over a data structure that can be folded which means that a functions gets called on each element to reduce the structure to a single value (Array, List and Map are all Foldable)

#[implicit]
let traversable : forall e . Traversable (Result e)

#[implicit]
let show ?e ?t : forall t e . [Show e] -> [Show t] -> Show (Result e t)

Show a represents a conversion function from a to a readable string.