mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
CCOpt.get
This commit is contained in:
parent
22343b4469
commit
1e07897da8
2 changed files with 8 additions and 0 deletions
|
|
@ -92,6 +92,10 @@ let fold f acc o = match o with
|
|||
| None -> acc
|
||||
| Some x -> f acc x
|
||||
|
||||
let get default x = match x with
|
||||
| None -> default
|
||||
| Some y -> y
|
||||
|
||||
let get_exn = function
|
||||
| Some x -> x
|
||||
| None -> invalid_arg "CCOpt.get_exn"
|
||||
|
|
|
|||
|
|
@ -60,6 +60,10 @@ val iter : ('a -> unit) -> 'a t -> unit
|
|||
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||
(** Fold on 0 or 1 elements *)
|
||||
|
||||
val get : 'a -> 'a t -> 'a
|
||||
(** [get default x] unwraps [x], but if [x = None] it returns [default] instead.
|
||||
@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] *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue