package bos
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=f8e8c24730dd6c54fafb9741cd09a7075f77a9f5c386497cab8693a93d35c6d3
md5=d5a4cef854a8dc07ccc2a4cc8d0a26eb
doc/bos.setup/Bos_setup/R/index.html
Module Bos_setup.RSource
include module type of struct include Rresult.R end
Results
The type for results.
ok v is Ok v.
error e is Error e.
reword_error reword r is:
rifr = Ok vError (reword e)ifr = Error e
get r is v if r = Ok v and
get_error r is e if r = Error e and
Composing results
bind r f is f v if r = Ok v and r if r = Error _.
map f r is bind (fun v -> ret (f v)) r.
join r is v if r = Ok v and r otherwise.
val (>>=) :
('a, 'b) Result.result ->
('a -> ('c, 'b) Result.result) ->
('c, 'b) Result.resultr >>= f is bind r f.
r >>| f is map r f.
Infix operators.
Error messages
The type for (error) messages.
msgf fmt ... formats a message according to fmt.
pp_msg ppf m prints m on ppf.
error_msg s is error (`Msg s).
error_msgf fmt ... is an error message formatted according to fmt.
val reword_error_msg :
?replace:bool ->
(string -> msg) ->
('a, msg) Result.result ->
('a, [> msg ]) Result.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.result ->
('a, [> msg ]) Result.resulterror_to_msg pp_error r converts errors in r with pp_error to an error message.
err_msg_to_invalid_arg r is v if r = Ok v and
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).
Trapping unexpected exceptions
Getting rid of null was not enough.
The type for exception traps.
pp_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.
Pretty printing
val pp :
ok:(Format.formatter -> 'a -> unit) ->
error:(Format.formatter -> 'b -> unit) ->
Format.formatter ->
('a, 'b) Result.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.result ->
unitdump ~ok ~error formats an OCaml result value using ok or error according to case, no parentheses are added.
Predicates and comparison
is_ok r is true iff r = Ok _.
is_error r is true iff r = Error _.
val equal :
ok:('a -> 'a -> bool) ->
error:('b -> 'b -> bool) ->
('a, 'b) Result.result ->
('a, 'b) Result.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.result ->
('a, 'b) Result.result ->
intcompare ~ok ~error r r' totally orders r and r' using ok and error.
Converting
to_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.
to_presult r is r as a polymorphic variant result value.
of_presult pr is pr as a result value.
Ignoring errors
Warning. Using these functions is, most of the time, a bad idea.
ignore_error ~use r is v if r = Ok v and use e if r = Error e.
val kignore_error :
use:('b -> ('a, 'c) Result.result) ->
('a, 'b) Result.result ->
('a, 'c) Result.resultkignore_error ~use r is r if r = Ok v and use e if r = Error e.