]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
Adds `join' to the Opt module
authorMatthias Goergens <matthias.goergens@citrix.com>
Tue, 2 Feb 2010 16:07:11 +0000 (16:07 +0000)
committerMatthias Goergens <matthias.goergens@citrix.com>
Tue, 2 Feb 2010 16:07:11 +0000 (16:07 +0000)
`join' collapses (Some (Some a)) down to (Some a), and gives Nothing otherwise.

Signed-off-by: Matthias Goergens <matthias.goergens@citrix.com>
stdext/opt.ml
stdext/opt.mli

index 31752088b1ccac1614847b3049d0fb348b59bc5c..8c39fb13754a6d3ce57c68fdfa32572794b522b9 100644 (file)
@@ -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
+
index aafa63ef5301a7a61dce76ef63b0bf0f96940e19..fd3147c6600a1dd9ae059a74804bdcffe136d79d 100644 (file)
@@ -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