Page
Library
Module
Module type
Parameter
Class
Class type
Source
Rresult.RResult value combinators.
type ('a, 'b) t = ('a, 'b) resultThe type for results.
val ok : 'a -> ('a, 'b) resultok v is Ok v.
val error : 'b -> ('a, 'b) resulterror e is Error e.
reword_error reword r is:
r if r = Ok vError (reword e) if r = Error eval get_ok : ('a, 'b) result -> 'aget_ok r is v if r = Ok v and raises Invalid_argument otherwise.
val get_error : ('a, 'b) result -> 'bget_error r is e if r = Error e and raises Invalid_argument otherwise.
bind r f is f v if r = Ok v and r if r = Error _.
module Infix : sig ... endInfix operators.
val msg : string -> [> msg ]msg s is `Msg s.
val msgf : ('a, Format.formatter, unit, [> msg ]) format4 -> 'amsgf fmt ... formats a message according to fmt.
val pp_msg : Format.formatter -> msg -> unitpp_msg ppf m prints m on ppf.
val error_msgf :
('a, Format.formatter, unit, ('b, [> msg ]) result) format4 ->
'aerror_msgf fmt ... is an error message formatted according to fmt.
val reword_error_msg :
?replace:bool ->
(string -> msg) ->
('a, msg) result ->
('a, [> msg ]) resultreword_error_msg ~replace reword r is like reword_error except if replace is false (default), the result of reword old_msg is concatened, on a new line to the old message.
val error_to_msg :
pp_error:(Format.formatter -> 'b -> unit) ->
('a, 'b) result ->
('a, [> msg ]) resulterror_to_msg ~pp_error r converts errors in r with pp_error to an error message.
open_error_msg r allows to combine a closed error message variant with other variants.
failwith_error_msg r raises Failure m if r is Error (`Msg m).
Getting rid of null was not enough.
The type for exception traps.
val pp_exn_trap : Format.formatter -> exn_trap -> unitpp_exn_trap ppf bt prints bt on ppf.
trap_exn f v is f v and traps any exception that may occur as an exception trap error.
error_exn_trap_to_msg r converts exception trap errors in r to an error message.
open_error_exn_trap r allows to combine a closed exception trap error variant with other variants.
val pp :
ok:(Format.formatter -> 'a -> unit) ->
error:(Format.formatter -> 'b -> unit) ->
Format.formatter ->
('a, 'b) result ->
unitpp ~ok ~error ppf r prints r on ppf using ok and error according to r.
val dump :
ok:(Format.formatter -> 'a -> unit) ->
error:(Format.formatter -> 'b -> unit) ->
Format.formatter ->
('a, 'b) result ->
unitdump ~ok ~error formats an OCaml result value using ok or error according to case, no parentheses are added.
val is_ok : ('a, 'b) result -> boolis_ok r is true iff r = Ok _.
val is_error : ('a, 'b) result -> boolis_error r is true iff r = Error _.
val equal :
ok:('a -> 'a -> bool) ->
error:('b -> 'b -> bool) ->
('a, 'b) result ->
('a, 'b) result ->
boolequal ~ok ~error r r' tests r and r' for equality using ok and error.
val compare :
ok:('a -> 'a -> int) ->
error:('b -> 'b -> int) ->
('a, 'b) result ->
('a, 'b) result ->
intcompare ~ok ~error r r' totally orders r and r' using ok and error.
val to_option : ('a, 'b) result -> 'a optionto_option r is Some v if r = Ok v and None otherwise.
of_option ~none r is Ok v if r = Some v and none () otherwise.
val to_presult : ('a, 'b) result -> [> `Ok of 'a | `Error of 'b ]to_presult r is r as a polymorphic variant result value.
val of_presult : [< `Ok of 'a | `Error of 'b ] -> ('a, 'b) resultof_presult pr is pr as a result value.
Warning. Using these functions is, most of the time, a bad idea.
val ignore_error : use:('b -> 'a) -> ('a, 'b) result -> 'aignore_error ~use r is v if r = Ok v and use e if r = Error e.