From 5a2b1eaffba59dc6459e18f735616f9f5fa70909 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Tue, 2 Feb 2010 16:07:11 +0000 Subject: [PATCH] Adds `join' to the Opt module `join' collapses (Some (Some a)) down to (Some a), and gives Nothing otherwise. Signed-off-by: Matthias Goergens --- stdext/opt.ml | 5 +++++ stdext/opt.mli | 1 + 2 files changed, 6 insertions(+) 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 -- 2.39.5