]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
The module stdext/Listext got a safe_head function that wraps hd in an option type.
authorMatthias Goergens <Matthias.Goergens@citrix.com>
Thu, 17 Jun 2010 21:16:18 +0000 (22:16 +0100)
committerMatthias Goergens <Matthias.Goergens@citrix.com>
Thu, 17 Jun 2010 21:16:18 +0000 (22:16 +0100)
Signed-off-by: Matthias Goergens <Matthias.Goergens@citrix.com>
stdext/listext.ml
stdext/listext.mli

index 9023569abc2bf2085fe2d099cf7b7409863b4ef2..5f9e1c7c5b0e163e4f43e69c8afb09eb77a3cd20 100644 (file)
@@ -193,6 +193,10 @@ let rec tails = function
     | [] -> [[]]
     | (_::xs) as l -> l :: tails xs
 
+let safe_hd = function
+       | a::_ -> Some a
+       | [] -> None
+
 let rec replace_assoc key new_value = function
        | [] -> []
        | (k, _) as p :: tl ->
index d1f8b1e8b193bda7301000c37d7093cc0887d71a..66c0729f776954b4107c6837a7281fb835474bb5 100644 (file)
@@ -176,6 +176,7 @@ module List :
     val take : int -> 'a list -> 'a list
        
     val tails : 'a list -> ('a list) list
+       val safe_hd : 'a list -> 'a option
 
        (** Replace the value belonging to a key in an association list. *)
        val replace_assoc : 'a -> 'b -> ('a * 'b) list -> ('a * 'b) list