mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCError.catch, in prevision of the future standard Result.t type
This commit is contained in:
parent
ebdf201161
commit
fb8e9078a3
2 changed files with 12 additions and 0 deletions
|
|
@ -92,6 +92,10 @@ let get_exn = function
|
|||
| `Ok x -> x
|
||||
| `Error _ -> raise (Invalid_argument "CCError.get_exn")
|
||||
|
||||
let catch e ~ok ~err = match e with
|
||||
| `Ok x -> ok x
|
||||
| `Error y -> err y
|
||||
|
||||
let flat_map f e = match e with
|
||||
| `Ok x -> f x
|
||||
| `Error s -> `Error s
|
||||
|
|
|
|||
|
|
@ -75,6 +75,14 @@ val get_exn : ('a, _) t -> 'a
|
|||
whenever possible.
|
||||
@raise Invalid_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 NEXT_RELEASE *)
|
||||
|
||||
val flat_map : ('a -> ('b, 'err) t) -> ('a, 'err) t -> ('b, 'err) t
|
||||
|
||||
val (>|=) : ('a, 'err) t -> ('a -> 'b) -> ('b, 'err) t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue