Source

spotlib / lib / result.mli

The default branch has multiple heads

Full commit
type ('a, 'error) t = [`Ok of 'a | `Error of 'error]

val catch : (fail:('error -> 'exn) -> 'a) -> [> ('a, 'error) t]
(** [catch f] runs [f ~fail]. 

    If [f ~fail] returns a value [v] then [catch f] returns [`Ok v].

    If [f ~fail] calls [fail e], then the execution of the [f ~fail] immediately
    exists and [catch f] returns [`Error e]

    Any exception raised in [f ~fail] is not caught.
*)

val catch_exn : (unit -> 'a) -> [> `Error of exn | `Ok of 'a ]
(** [catch_exn f] runs [f ()]. 

    If [f ()] returns a value [v] then [catch f] returns [`Ok v].

    If an exception [exn] raised in [f ()], [catch f] returns [`Error exn].
*)