mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
parent
da2c9e7c7c
commit
29a75daac1
3 changed files with 18 additions and 0 deletions
|
|
@ -33,3 +33,4 @@
|
|||
- Metin Akat (@loxs)
|
||||
- Francois Berenger (@UnixJunkie)
|
||||
- Hongchang Wu (@hongchangwu)
|
||||
- Nathan Rebours (@NathanReb)
|
||||
|
|
|
|||
|
|
@ -83,6 +83,19 @@ let iter f e = match e with
|
|||
| Ok x -> f x
|
||||
| Error _ -> ()
|
||||
|
||||
let iter_err f e = match e with
|
||||
| Ok _ -> ()
|
||||
| Error err -> f err
|
||||
|
||||
(*$R iter_err
|
||||
let called_with = ref None in
|
||||
let f e = called_with := Some e in
|
||||
iter_err f (Ok 1);
|
||||
assert_bool "should not apply when Ok" (!called_with = None);
|
||||
iter_err f (Error 1);
|
||||
assert_bool "should apply f to Error" (!called_with = Some 1)
|
||||
*)
|
||||
|
||||
exception Get_error
|
||||
|
||||
let get_exn = function
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ val map2 : ('a -> 'b) -> ('err1 -> 'err2) -> ('a, 'err1) t -> ('b, 'err2) t
|
|||
val iter : ('a -> unit) -> ('a, _) t -> unit
|
||||
(** Apply the function only in case of [Ok]. *)
|
||||
|
||||
val iter_err : ('err -> unit) -> (_, 'err) t -> unit
|
||||
(** Apply the function in case of [Error].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
exception Get_error
|
||||
|
||||
val get_exn : ('a, _) t -> 'a
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue