Add CCOpt.get_exn_or and deprecate CCOpt.get_exn

This commit is contained in:
Daniil Baturin 2021-04-28 00:09:03 +07:00 committed by Simon Cruanes
parent 0d9a3b82fa
commit 3628feed9c
2 changed files with 11 additions and 0 deletions

View file

@ -110,6 +110,10 @@ let get_exn = function
| Some x -> x | Some x -> x
| None -> invalid_arg "CCOpt.get_exn" | None -> invalid_arg "CCOpt.get_exn"
let get_exn_or msg = function
| Some x -> x
| None -> invalid_arg msg
let get_lazy default_fn x = match x with let get_lazy default_fn x = match x with
| None -> default_fn () | None -> default_fn ()
| Some y -> y | Some y -> y

View file

@ -88,7 +88,14 @@ val value : 'a t -> default:'a -> 'a
@since 2.8 *) @since 2.8 *)
val get_exn : 'a t -> 'a val get_exn : 'a t -> 'a
[@@ocaml.deprecated "use CCOpt.get_exn_or instead"]
(** [get_exn o] returns [x] if [o] is [Some x] or fails if [o] is [None]. (** [get_exn o] returns [x] if [o] is [Some x] or fails if [o] is [None].
@raise Invalid_argument if the option is [None].
@deprecated use {!get_exn_or} instead
*)
val get_exn_or : string -> 'a t -> 'a
(** [get_exn msg o] returns [x] if [o] is [Some x] or fails with [Invalid_argument msg] if [o] is [None].
@raise Invalid_argument if the option is [None]. *) @raise Invalid_argument if the option is [None]. *)
val get_lazy : (unit -> 'a) -> 'a t -> 'a val get_lazy : (unit -> 'a) -> 'a t -> 'a