CCError.{iter,get_exn}

This commit is contained in:
Simon Cruanes 2014-09-17 14:09:13 +02:00
parent 3615d208dc
commit 0aaae830bc
2 changed files with 17 additions and 0 deletions

View file

@ -72,6 +72,14 @@ let map2 f g e = match e with
| `Ok x -> `Ok (f x)
| `Error s -> `Error (g s)
let iter f e = match e with
| `Ok x -> f x
| `Error _ -> ()
let get_exn = function
| `Ok x -> x
| `Error _ -> raise (Invalid_argument "CCError.get_exn")
let flat_map f e = match e with
| `Ok x -> f x
| `Error s -> `Error s

View file

@ -56,6 +56,15 @@ val map2 : ('a -> 'b) -> (string -> string) -> 'a t -> 'b t
(** Same as {!map}, but also with a function that can transform
the error message in case of failure *)
val iter : ('a -> unit) -> 'a t -> unit
(** Apply the function only in case of `Ok *)
val get_exn : 'a t -> 'a
(** Extract the value [x] from [`Ok x], fails otherwise.
You should be careful with this function, and favor other combinators
whenever possible.
@raise Invalid_argument if the value is an error. *)
val flat_map : ('a -> 'b t) -> 'a t -> 'b t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t