add CCOpt.value to improve compat with Stdlib.Option

This commit is contained in:
Simon Cruanes 2019-11-20 17:49:49 -06:00
parent 3804dbff86
commit bd4e4d311d
2 changed files with 7 additions and 0 deletions

View file

@ -106,6 +106,9 @@ let fold f acc o = match o with
let get_or ~default x = match x with
| None -> default
| Some y -> y
let value x ~default = match x with
| None -> default
| Some y -> y
let get_exn = function
| Some x -> x

View file

@ -72,6 +72,10 @@ val get_or : default:'a -> 'a t -> 'a
returns [default] if [o = None].
@since 0.18 *)
val value : 'a t -> default:'a -> 'a
(** Similar to the stdlib's [Option.value] and to {!get_or}.
@since NEXT_RELEASE *)
val get_exn : 'a t -> 'a
(** Open the option, possibly failing if it is [None].
@raise Invalid_argument if the option is [None]. *)