From c99f7818c39b49bab54eecb06c8773f8b9db589e Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 27 Apr 2021 13:21:34 -0400 Subject: [PATCH] udpate doc and add test --- src/core/CCOpt.ml | 5 +++++ src/core/CCOpt.mli | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index 10974bf5..7527077a 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -114,6 +114,11 @@ let get_exn_or msg = function | Some x -> x | None -> invalid_arg msg +(*$T + (try get_exn_or "ohno" (None:unit option); false with Invalid_argument s->s= "ohno") + 123 = get_exn_or "yes" (Some 123) +*) + 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 98992cf8..64f4b527 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -95,8 +95,10 @@ val get_exn : 'a t -> 'a *) 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]. *) +(** [get_exn_or 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]. + @since NEXT_RELEASE *) val get_lazy : (unit -> 'a) -> 'a t -> 'a (** [get_lazy default_fn o] unwraps [o], but if [o] is [None] it returns [default_fn ()] instead.