diff --git a/src/core/CCHashtbl.ml b/src/core/CCHashtbl.ml index 4bf972f0..580e6f29 100644 --- a/src/core/CCHashtbl.ml +++ b/src/core/CCHashtbl.ml @@ -84,6 +84,14 @@ module type S = sig val values : 'a t -> 'a sequence (** Iterate on values in the table *) + val keys_list : ('a, 'b) Hashtbl.t -> 'a list + (** [keys t] is the list of keys in [t]. + @since NEXT_RELEASE *) + + val values_list : ('a, 'b) Hashtbl.t -> 'b list + (** [values t] is the list of values in [t]. + @since NEXT_RELEASE *) + val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list (** Map on a hashtable's items, collect into a list *) @@ -111,6 +119,9 @@ module Make(X : Hashtbl.HashedType) = struct let values tbl k = iter (fun _ v -> k v) tbl + let keys_list tbl = Hashtbl.fold (fun k _ a -> k::a) tbl [] + let values_list tbl = Hashtbl.fold (fun _ v a -> v::a) tbl [] + let map_list f h = fold (fun x y acc -> f x y :: acc) diff --git a/src/core/CCHashtbl.mli b/src/core/CCHashtbl.mli index 9327745d..b862bcad 100644 --- a/src/core/CCHashtbl.mli +++ b/src/core/CCHashtbl.mli @@ -45,10 +45,12 @@ val values : ('a,'b) Hashtbl.t -> 'b sequence (** Iterate on values in the table *) val keys_list : ('a, 'b) Hashtbl.t -> 'a list -(** [keys t] is the list of keys in [t]. *) +(** [keys t] is the list of keys in [t]. + @since NEXT_RELEASE *) val values_list : ('a, 'b) Hashtbl.t -> 'b list -(** [values t] is the list of values in [t]. *) +(** [values t] is the list of values in [t]. + @since NEXT_RELEASE *) val map_list : ('a -> 'b -> 'c) -> ('a, 'b) Hashtbl.t -> 'c list (** Map on a hashtable's items, collect into a list *) @@ -79,6 +81,14 @@ module type S = sig val values : 'a t -> 'a sequence (** Iterate on values in the table *) + val keys_list : ('a, 'b) Hashtbl.t -> 'a list + (** [keys t] is the list of keys in [t]. + @since NEXT_RELEASE *) + + val values_list : ('a, 'b) Hashtbl.t -> 'b list + (** [values t] is the list of values in [t]. + @since NEXT_RELEASE *) + val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list (** Map on a hashtable's items, collect into a list *)