CCError.map2

This commit is contained in:
Simon Cruanes 2014-06-27 15:25:34 +02:00
parent c340ad3358
commit e6dd5db678
2 changed files with 8 additions and 0 deletions

View file

@ -49,6 +49,10 @@ let map f e = match e with
| `Ok x -> `Ok (f x) | `Ok x -> `Ok (f x)
| `Error s -> `Error s | `Error s -> `Error s
let map2 f g e = match e with
| `Ok x -> `Ok (f x)
| `Error s -> `Error (g s)
let flat_map f e = match e with let flat_map f e = match e with
| `Ok x -> f x | `Ok x -> f x
| `Error s -> `Error s | `Error s -> `Error s

View file

@ -47,6 +47,10 @@ val of_exn : exn -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t val map : ('a -> 'b) -> 'a t -> 'b t
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 flat_map : ('a -> 'b t) -> 'a t -> 'b t val flat_map : ('a -> 'b t) -> 'a t -> 'b t
val guard : (unit -> 'a) -> 'a t val guard : (unit -> 'a) -> 'a t