From 61c258b3e9c78cfa63dba73d0fad6759bccc4d1f Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Thu, 20 May 2004 09:27:06 +0000 Subject: [PATCH] added iterators over registry contents (fold, iter, to_list) --- helm/ocaml/registry/helm_registry.ml | 4 ++++ helm/ocaml/registry/helm_registry.mli | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/helm/ocaml/registry/helm_registry.ml b/helm/ocaml/registry/helm_registry.ml index 0c7b43723..2b6461b56 100644 --- a/helm/ocaml/registry/helm_registry.ml +++ b/helm/ocaml/registry/helm_registry.ml @@ -310,6 +310,10 @@ let load_from ?path fname = end else load_from_absolute fname +let fold f init = Hashtbl.fold (fun k v acc -> f acc k v) registry init +let iter f = fold (fun _ k v -> f k v) () +let to_list () = fold (fun acc k v -> (k, v) :: acc) [] + (* DEBUGGING ONLY *) let dump () = Hashtbl.iter (fun k v -> printf "%s = %s\n" k v) registry diff --git a/helm/ocaml/registry/helm_registry.mli b/helm/ocaml/registry/helm_registry.mli index 1f40b5453..62e85c5f1 100644 --- a/helm/ocaml/registry/helm_registry.mli +++ b/helm/ocaml/registry/helm_registry.mli @@ -108,6 +108,10 @@ val set: key:string -> value:string -> unit * raise Key_not_found until the key will be redefined *) val unset: string -> unit +val fold: ('a -> string -> string -> 'a) -> 'a -> 'a +val iter: (string -> string -> unit) -> unit +val to_list: unit -> (string * string) list + (** {2 Typed interface} * Three basic types are supported: strings, int and strings list. Strings * correspond literally to what is written inside double quotes; int to the -- 2.39.2