module BatResult:sig..end
Monadic results of computations that can raise exceptions
type('a, 'b)t =('a, 'b) BatPervasives.result=
| |
Ok of |
| |
Bad of |
The type of a result. A result is either Ok x carrying the
normal return value x or is Bad e carrying some indication of an
error. The value associated with a bad result is usually an exception
(exn) that can be raised.
val catch : ('a -> 'b) -> 'a -> ('b, exn) tExecute a function and catch any exception as a result. This function encapsulates code that could throw an exception and returns that exception as a value.
val catch2 : ('a -> 'b -> 'c) -> 'a -> 'b -> ('c, exn) tAs catch but two parameters. This saves a closure construction
val catch3 : ('a -> 'b -> 'c -> 'd) -> 'a -> 'b -> 'c -> ('d, exn) tAs catch but three parameters. This saves a closure construction
val get : ('a, exn) t -> 'aget (Ok x) returns x, and get (Bad e) raises e. This
function is, in a way, the opposite of the catch function
val default : 'a -> ('a, 'b) t -> 'adefault d r evaluates to d if r is Bad else x when r is
Ok x
val map : ('a -> 'b) -> ('a, 'c) t -> ('b, 'c) tmap f (Ok x) returns Ok (f x) and map f (Bad e) returns Bad e.
val map_both : ('a1 -> 'a2) ->
('b1 -> 'b2) -> ('a1, 'b1) t -> ('a2, 'b2) tmap_both f g (Ok x) returns Ok (f x) and map_both f g (Bad e) returns Bad (g e).
val map_default : 'b -> ('a -> 'b) -> ('a, 'c) t -> 'bmap_default d f r evaluates to d if r is Bad else f x
when r is Ok x
val is_ok : ('a, 'b) t -> boolis_ok (Ok _) is true, otherwise false.
val is_bad : ('a, 'b) t -> boolis_bad (Bad _) is true, otherwise false
val is_exn : exn -> ('a, exn) t -> boolis_exn e1 r is true iff r is Bad e2 with e1=e2
val of_option : 'a option -> ('a, unit) tConvert an option to a result
val to_option : ('a, 'b) t -> 'a optionConvert a result to an option
This monad is very similar to the option monad, but instead of
being None when an error occurs, the first error in the sequence is
preserved as the return value.
module Monad:sig..end
module Infix:sig..end
This infix module provides the operator (>>=)
val print : ('b BatInnerIO.output -> 'a -> unit) ->
'b BatInnerIO.output -> ('a, exn) t -> unitPrint a result as Ok(x) or Bad(exn)