# HG changeset patch # User Matthias Goergens # Date 1274194687 -3600 # Node ID efa9be86851509d215e5b2a43c3c94ca00b09c9b # Parent 6901fb31a2a0b4bcaa0c9c5e7b86dcf611393303 stdext/Listext got a function make_assoc to build Lisp-like assoc lists Signed-off-by: Matthias Goergens diff --git a/stdext/listext.ml b/stdext/listext.ml --- a/stdext/listext.ml +++ b/stdext/listext.ml @@ -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 = fu else p :: replace_assoc key new_value tl +let make_assoc op l = map (fun item -> item, op item) l + end diff --git a/stdext/listext.mli b/stdext/listext.mli --- a/stdext/listext.mli +++ b/stdext/listext.mli @@ -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