Extract the value x from `Ok x, fails otherwise. You should be careful with this function, and favor other combinators whenever possible.
raisesInvalid_argument
if the value is an error.
val catch : ('a, 'err)t->ok:('a->'b)->err:('err->'b)->'b
catch e ~ok ~err calls either ok or err depending on the value of e. This is useful for code that does not want to depend on the exact definition of ('a, 'b) t used, for instance once OCaml gets a standard Result.t type.
since 0.12
val flat_map : ('a->('b, 'err)t)->('a, 'err)t->('b, 'err)t
val (<*>) : ('a->'b, 'err)t->('a, 'err)t->('b, 'err)t
a <*> 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.
join 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.
since 0.15
val both : ('a, 'err)t->('b, 'err)t->('a * 'b, 'err)t
both 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.
choose 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)t
retry 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.
One can register exception printers here, so they will be used by guard, wrap1, etc. The printers should succeed (print) on exceptions they can deal with, and re-raise the exception otherwise. For instance if I register a printer for Not_found, it could look like:
CCError.register_printer
(fun buf exn -> match exn with
| Not_found -> Buffer.add_string buf "Not_found"
| _ -> raise exn
);;
This way a printer that doesn't know how to deal with an exception will let other printers do it.