diff --git a/bij.ml b/bij.ml index d19727a1..7eadb52e 100644 --- a/bij.ml +++ b/bij.ml @@ -92,6 +92,21 @@ let with_version v t = else raise (DecodingError ("expected version " ^ v))) (pair string_ t) +let array_ m = + map + ~inject:(fun a -> Array.to_list a) + ~extract:(fun l -> Array.of_list l) + (list_ m) + +let hashtbl ma mb = + map + ~inject:(fun h -> Hashtbl.fold (fun k v l -> (k,v)::l) h []) + ~extract:(fun l -> + let h = Hashtbl.create 5 in + List.iter (fun (k,v) -> Hashtbl.add h k v) l; + h) + (list_ (pair ma mb)) + (** {2 Source of parsing} *) module type SOURCE = sig diff --git a/bij.mli b/bij.mli index 41d8217a..53f7749f 100644 --- a/bij.mli +++ b/bij.mli @@ -68,6 +68,9 @@ val with_version : string -> 'a t -> 'a t (** Guards the values with a given version. Only values encoded with the same version will fit. *) +val array_ : 'a t -> 'a array t +val hashtbl : 'a t -> 'b t -> ('a, 'b) Hashtbl.t t + (** {2 Exceptions} *) exception EOF