WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH] CP-1622: Listext function to replace the value for a k

To: xen-api <xen-api@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-API] [PATCH] CP-1622: Listext function to replace the value for a key in an assoc list
From: Rob Hoes <rob.hoes@xxxxxxxxxx>
Date: Tue, 16 Feb 2010 23:09:04 +0000
Delivery-date: Tue, 16 Feb 2010 15:09:36 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Rob Hoes <rob.hoes@xxxxxxxxxx>
CP-1622: Listext function to replace the value for a key in an assoc list

Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>

diff -r 3e1beafe76b5 stdext/listext.ml
--- a/stdext/listext.ml Tue Feb 16 22:40:11 2010 +0000
+++ b/stdext/listext.ml Tue Feb 16 22:47:58 2010 +0000
@@ -192,4 +192,13 @@
 let rec tails = function
     | [] -> [[]]
     | (_::xs) as l -> l :: tails xs
+
+let rec replace_assoc key new_value = function
+       | [] -> []
+       | (k, _) as p :: tl ->
+               if k = key then
+                       (key, new_value) :: tl
+               else
+                       p :: replace_assoc key new_value tl
+
 end
diff -r 3e1beafe76b5 stdext/listext.mli
--- a/stdext/listext.mli        Tue Feb 16 22:40:11 2010 +0000
+++ b/stdext/listext.mli        Tue Feb 16 22:47:58 2010 +0000
@@ -177,4 +177,6 @@
        
     val tails : 'a list -> ('a list) list
 
+       (** Replace the value belonging to a key in an association list. *)
+       val replace_assoc : 'a -> 'b -> ('a * 'b) list -> ('a * 'b) list
   end

Attachment: list-replace-assoc
Description: Text document

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-API] [PATCH] CP-1622: Listext function to replace the value for a key in an assoc list, Rob Hoes <=