Dump Hashtbl.t to list or assoc list

Is there no easy or built-in way to dump all keys and/or values of a hash table to a list or assoc list? Lists are easier to use when asserting equality in tests, like test_eq.

I find iter, but no map, which is weird, or?

Alternatively, dump Hashtbl.t to Seq.t and then to assoc list.

https://v2.ocaml.org/api/Hashtbl.html

https://v2.ocaml.org/api/Seq.html

Check this thread Module 'Stream' removed from 5.0 standard library? - #34 by raphael-proust

1 Like
let hashtbl_to_list table =
  Hashtbl.fold (fun key value -> List.cons (key, value)) table []
1 Like