]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
stdext/Listext got a function make_assoc to build Lisp-like assoc lists
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 5f9e1c7c5b0e163e4f43e69c8afb09eb77a3cd20..e7cbe3c5b8c38072d8fde818b9f96a6dd50362a4 100644 (file)
@@ -197,6 +197,8 @@ let safe_hd = function
        | a::_ -> Some a
        | [] -> None
 
+let make_assoc op l = map (fun item -> item, op item) l
+
 let rec replace_assoc key new_value = function
        | [] -> []
        | (k, _) as p :: tl ->
@@ -205,4 +207,6 @@ let rec replace_assoc key new_value = function
                else
                        p :: replace_assoc key new_value tl
 
+let make_assoc op l = map (fun item -> item, op item) l
+
 end
index b78252f7b88da62bb1fe9342e319315a87c4f5b5..31feb053e43d12505c017c62b14ac398be19b3a3 100644 (file)
@@ -180,4 +180,6 @@ sig
 
        (** Replace the value belonging to a key in an association list. *)
        val replace_assoc : 'a -> 'b -> ('a * 'b) list -> ('a * 'b) list
+
+       val make_assoc : ('a -> 'b) -> 'a list -> ('a * 'b) list
 end