# HG changeset patch # User Matthias Goergens # Date 1274191678 -3600 # Node ID 67bd0ed08bcd86f566600a14b18c887b19b977f8 # Parent 66365ae80cad7dce7ffee4e6a9cbbd28d7324450 The module stdext/Listext got a safe_head function that wraps hd in an option type. Signed-off-by: Matthias Goergens diff --git a/stdext/listext.ml b/stdext/listext.ml --- a/stdext/listext.ml +++ b/stdext/listext.ml @@ -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 -> diff --git a/stdext/listext.mli b/stdext/listext.mli --- a/stdext/listext.mli +++ b/stdext/listext.mli @@ -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