Add CCOpt.flatten

This commit is contained in:
Etienne Millon 2018-04-24 15:19:56 +02:00 committed by Simon Cruanes
parent d8caef8c02
commit bbda79bbcc
2 changed files with 14 additions and 0 deletions

View file

@ -208,3 +208,13 @@ let to_seq o k = match o with
let pp ppx out = function
| None -> Format.pp_print_string out "None"
| Some x -> Format.fprintf out "@[Some %a@]" ppx x
let flatten = function
| Some x -> x
| None -> None
(*$T
flatten None = None
flatten (Some None) = None
flatten (Some (Some 1)) = Some 1
*)

View file

@ -122,6 +122,10 @@ val (<+>) : 'a t -> 'a t -> 'a t
val choice : 'a t list -> 'a t
(** [choice] returns the first non-[None] element of the list, or [None]. *)
val flatten : 'a t t -> 'a t
(** [flatten] transforms [Some x] into [x].
@since NEXT_RELEASE *)
(** {2 Infix Operators}
@since 0.16 *)