From: Matthias Goergens Date: Tue, 2 Feb 2010 16:07:11 +0000 (+0000) Subject: Adds `join' to the Opt module X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=5a2b1eaffba59dc6459e18f735616f9f5fa70909;p=xcp%2Fxen-api-libs.git Adds `join' to the Opt module `join' collapses (Some (Some a)) down to (Some a), and gives Nothing otherwise. Signed-off-by: Matthias Goergens --- diff --git a/stdext/opt.ml b/stdext/opt.ml index 3175208..8c39fb1 100644 --- a/stdext/opt.ml +++ b/stdext/opt.ml @@ -54,3 +54,8 @@ let fold_right f opt accu = | None -> accu let cat_options a = List.map unbox (List.filter is_boxed a) + +let join = function + | Some (Some a) -> Some a + | _ -> None + diff --git a/stdext/opt.mli b/stdext/opt.mli index aafa63e..fd3147c 100644 --- a/stdext/opt.mli +++ b/stdext/opt.mli @@ -20,3 +20,4 @@ val to_list : 'a option -> 'a list val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b option -> 'a val fold_right : ('a -> 'b -> 'b) -> 'a option -> 'b -> 'b val cat_options : 'a option list -> 'a list +val join : ('a option) option -> 'a option