package preface

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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.

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

Addtional 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 catched 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.