Module Preface_stdlib.Try

Implementation for Try.t.

Try.t is a biased version of Result with the error fixed as an exception.

Type

type 'a t = ('a, exn) Stdlib.result

Implementation

Functor

module Functor : Preface_specs.FUNCTOR with type 'a t = 'a t

Alt

module Alt : Preface_specs.ALT with type 'a t = 'a t

Applicative

Try.t implements Preface_specs.APPLICATIVE and introduces an interface to define Preface_specs.TRAVERSABLE using Try as an iterable structure.

Selective

module Selective : Preface_specs.SELECTIVE with type 'a t = 'a t

Monad

Try.t implements Preface_specs.MONAD and introduces an interface to define Preface_specs.TRAVERSABLE using Try as an iterable structure.

Foldable

module Foldable : Preface_specs.FOLDABLE with type 'a t = 'a t

Invariant

module Invariant : Preface_specs.INVARIANT with type 'a t = 'a t

Additional functions

Additional functions to facilitate practical work with Try.t.

val pure : 'a -> 'a t

Create a value from 'a to 'a t.

val ok : 'a -> 'a t

Wrap a value into Ok.

val error : exn -> 'a t

Wrap an exception into Error.

val capture : (unit -> 'a) -> 'a t

capture f perform f and wrap the result into a t if the execution of f raise no exception, the result will be Ok result else, the caught exception if wrapped into Error exn.

val case : ('a -> 'b) -> (exn -> 'b) -> 'a t -> 'b

case f g x apply f if x is Ok, g if x is Error.

val to_validation : 'a t -> ('a, exn Nonempty_list.t) Validation.t

Project a Try into a Validation.

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

Equality between Try.t.

val pp : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit

Formatter for pretty-printing for Try.t.