mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-18 08:36:41 -05:00
Merge branch 'master' into list_counts
This commit is contained in:
commit
38635dd7ed
3 changed files with 15 additions and 0 deletions
|
|
@ -32,3 +32,4 @@
|
||||||
- Jules Aguillon (@julow)
|
- Jules Aguillon (@julow)
|
||||||
- Metin Akat (@loxs)
|
- Metin Akat (@loxs)
|
||||||
- Francois Berenger (@UnixJunkie)
|
- Francois Berenger (@UnixJunkie)
|
||||||
|
- Hongchang Wu (@hongchangwu)
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,15 @@ let get_or e ~default = match e with
|
||||||
| Ok x -> x
|
| Ok x -> x
|
||||||
| Error _ -> default
|
| Error _ -> default
|
||||||
|
|
||||||
|
let get_or_failwith = function
|
||||||
|
| Ok x -> x
|
||||||
|
| Error msg -> failwith msg
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
get_or_failwith (Ok 1) = 1
|
||||||
|
try ignore @@ get_or_failwith (Error "e"); false with Failure msg -> msg = "e"
|
||||||
|
*)
|
||||||
|
|
||||||
let map_or f e ~default = match e with
|
let map_or f e ~default = match e with
|
||||||
| Ok x -> f x
|
| Ok x -> f x
|
||||||
| Error _ -> default
|
| Error _ -> default
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,11 @@ val get_exn : ('a, _) t -> 'a
|
||||||
val get_or : ('a, _) t -> default:'a -> 'a
|
val get_or : ('a, _) t -> default:'a -> 'a
|
||||||
(** [get_or e ~default] returns [x] if [e = Ok x], [default] otherwise. *)
|
(** [get_or e ~default] returns [x] if [e = Ok x], [default] otherwise. *)
|
||||||
|
|
||||||
|
val get_or_failwith : ('a, string) t -> 'a
|
||||||
|
(** [get_or_failwith e] returns [x] if [e = Ok x], fails otherwise.
|
||||||
|
@raise Failure with [msg] if [e = Error msg].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val map_or : ('a -> 'b) -> ('a, 'c) t -> default:'b -> 'b
|
val map_or : ('a -> 'b) -> ('a, 'c) t -> default:'b -> 'b
|
||||||
(** [map_or f e ~default] returns [f x] if [e = Ok x], [default] otherwise. *)
|
(** [map_or f e ~default] returns [f x] if [e = Ok x], [default] otherwise. *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue