mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
CCError.{iter,get_exn}
This commit is contained in:
parent
3615d208dc
commit
0aaae830bc
2 changed files with 17 additions and 0 deletions
|
|
@ -72,6 +72,14 @@ let map2 f g e = match e with
|
||||||
| `Ok x -> `Ok (f x)
|
| `Ok x -> `Ok (f x)
|
||||||
| `Error s -> `Error (g s)
|
| `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
|
let flat_map f e = match e with
|
||||||
| `Ok x -> f x
|
| `Ok x -> f x
|
||||||
| `Error s -> `Error s
|
| `Error s -> `Error s
|
||||||
|
|
|
||||||
|
|
@ -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
|
(** Same as {!map}, but also with a function that can transform
|
||||||
the error message in case of failure *)
|
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 flat_map : ('a -> 'b t) -> 'a t -> 'b t
|
||||||
|
|
||||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue