diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index 9452aaf4..10974bf5 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -110,6 +110,10 @@ let get_exn = function | Some x -> x | 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 | None -> default_fn () | Some y -> y diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index f8a5d98e..98992cf8 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -88,7 +88,14 @@ val value : 'a t -> default:'a -> 'a @since 2.8 *) 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]. + @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]. *) val get_lazy : (unit -> 'a) -> 'a t -> 'a