module CCResult:sig..end
Uses the new "result" type from OCaml 4.03.
Since 0.16
type'asequence =('a -> unit) -> unit
type'aequal ='a -> 'a -> bool
type'aord ='a -> 'a -> int
type'aprinter =Format.formatter -> 'a -> unit
type('good, 'bad)t =('good, 'bad) Result.result=
| |
Ok of |
| |
Error of |
val return : 'a -> ('a, 'err) tval fail : 'err -> ('a, 'err) tval of_exn : exn -> ('a, string) tof_exn e uses Printexc to print the exception as a stringval of_exn_trace : exn -> ('a, string) tof_exn_trace e is similar to of_exn e, but it adds the stacktrace
to the error message.
Remember to call Printexc.record_backtrace true and compile with the
debug flag for this to work.
val fail_printf : ('a, Buffer.t, unit, ('b, string) t) Pervasives.format4 -> 'afail_printf format uses format to obtain an error message
and then returns Error msgval fail_fprintf : ('a, Format.formatter, unit, ('b, string) t) Pervasives.format4 ->
'afail_printf format uses format to obtain an error message
and then returns Error msgval add_ctx : string -> ('a, string) t -> ('a, string) tadd_ctx msg leaves Ok x untouched, but transforms
Error s into Error s' where s' contains the additional
context given by msgval add_ctxf : ('a, Format.formatter, unit,
('b, string) t -> ('b, string) t)
Pervasives.format4 -> 'aadd_ctxf format_message is similar to CCResult.add_ctx but with
Format for printing the message (eagerly).
Example: add_ctxf "message(number %d, foo: %B)" 42 true (Error "error)"
val map : ('a -> 'b) -> ('a, 'err) t -> ('b, 'err) tval map_err : ('err1 -> 'err2) -> ('a, 'err1) t -> ('a, 'err2) tval map2 : ('a -> 'b) ->
('err1 -> 'err2) -> ('a, 'err1) t -> ('b, 'err2) tCCResult.map, but also with a function that can transform
the error message in case of failureval iter : ('a -> unit) -> ('a, 'b) t -> unitexception Get_error
val get_exn : ('a, 'b) t -> 'ax from Ok x, fails otherwise.
You should be careful with this function, and favor other combinators
whenever possible.Get_error if the value is an error.val get_or : ('a, 'b) t -> default:'a -> 'aget_or e ~default returns x if e = Ok x, default otherwiseval map_or : ('a -> 'b) -> ('a, 'c) t -> default:'b -> 'bmap_or f e ~default returns f x if e = Ok x, default otherwiseval catch : ('a, 'err) t -> ok:('a -> 'b) -> err:('err -> 'b) -> 'bcatch e ~ok ~err calls either ok or err depending on
the value of e.val flat_map : ('a -> ('b, 'err) t) ->
('a, 'err) t -> ('b, 'err) t
val (>|=) : ('a, 'err) t -> ('a -> 'b) -> ('b, 'err) t
val (>>=) : ('a, 'err) t ->
('a -> ('b, 'err) t) -> ('b, 'err) t
val equal : ?err:'err equal ->
'a equal -> ('a, 'err) t equal
val compare : ?err:'err ord ->
'a ord -> ('a, 'err) t ord
val fold : ok:('a -> 'b) -> error:('err -> 'b) -> ('a, 'err) t -> 'bfold ~ok ~error e opens e and, if e = Ok x, returns
ok x, otherwise e = Error s and it returns error s.val fold_ok : ('a -> 'b -> 'a) -> 'a -> ('b, 'c) t -> 'afold_ok f acc r will compute f acc x if r=Ok x,
and return acc otherwise, as if the result were a mere option.val is_ok : ('a, 'err) t -> boolval is_error : ('a, 'err) t -> boolval guard : (unit -> 'a) -> ('a, exn) tguard f runs f () and returns its result wrapped in Ok. If
f () raises some exception e, then it fails with Error eval guard_str : (unit -> 'a) -> ('a, string) t
val guard_str_trace : (unit -> 'a) -> ('a, string) tCCResult.guard_str but uses CCResult.of_exn_trace instead of CCResult.of_exn so
that the stack trace is printed.val wrap1 : ('a -> 'b) -> 'a -> ('b, exn) tCCResult.guard but gives the function one argument.val wrap2 : ('a -> 'b -> 'c) -> 'a -> 'b -> ('c, exn) tCCResult.guard but gives the function two arguments.val wrap3 : ('a -> 'b -> 'c -> 'd) -> 'a -> 'b -> 'c -> ('d, exn) tCCResult.guard but gives the function three arguments.val pure : 'a -> ('a, 'err) tCCResult.returnval (<*>) : ('a -> 'b, 'err) t -> ('a, 'err) t -> ('b, 'err) ta <*> b evaluates a and b, and, in case of success, returns
Ok (a b). Otherwise, it fails, and the error of a is chosen
over the error of b if both fail.val join : (('a, 'err) t, 'err) t -> ('a, 'err) tjoin t, in case of success, returns Ok o from Ok (Ok o). Otherwise,
it fails with Error e where e is the unwrapped error of t.val both : ('a, 'err) t -> ('b, 'err) t -> ('a * 'b, 'err) tboth a b, in case of success, returns Ok (o, o') with the ok values
of a and b. Otherwise, it fails, and the error of a is chosen over the
error of b if both fail.module Infix:sig..end
val map_l : ('a -> ('b, 'err) t) -> 'a list -> ('b list, 'err) t
val fold_l : ('b -> 'a -> ('b, 'err) t) -> 'b -> 'a list -> ('b, 'err) t
val fold_seq : ('b -> 'a -> ('b, 'err) t) ->
'b -> 'a sequence -> ('b, 'err) tval choose : ('a, 'err) t list -> ('a, 'err list) tchoose l selects a member of l that is a Ok _ value,
or returns Error l otherwise, where l is the list of errors.val retry : int -> (unit -> ('a, 'err) t) -> ('a, 'err list) tretry n f calls f at most n times, returning the first result
of f () that doesn't fail. If f fails n times, retry n f fails
with the list of successive errors.module type MONAD =sig..end
module Traverse(M:MONAD):sig..end
val to_opt : ('a, 'b) t -> 'a option
val of_opt : 'a option -> ('a, string) t
val to_seq : ('a, 'b) t -> 'a sequence
type('a, 'b)error =[ `Error of 'b | `Ok of 'a ]
val of_err : ('a, 'b) error -> ('a, 'b) tval to_err : ('a, 'b) t -> ('a, 'b) errorval pp : 'a printer -> ('a, string) t printer
val pp' : 'a printer ->
'e printer -> ('a, 'e) t printer