From 19e87aae5443457dbc5433ece859f66bb4eab4c9 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Thu, 17 Jun 2010 22:16:18 +0100 Subject: [PATCH] stdext/Listext got a function make_assoc to build Lisp-like assoc lists Signed-off-by: Matthias Goergens --- stdext/listext.ml | 4 ++++ stdext/listext.mli | 2 ++ 2 files changed, 6 insertions(+) diff --git a/stdext/listext.ml b/stdext/listext.ml index 5f9e1c7..e7cbe3c 100644 --- 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 = function 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 index b78252f..31feb05 100644 --- 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 -- 2.39.5