added a few helpers to Bij

This commit is contained in:
Simon Cruanes 2013-05-20 12:36:55 +02:00
parent 44bd29766c
commit ec41b0397d
2 changed files with 18 additions and 0 deletions

15
bij.ml
View file

@ -92,6 +92,21 @@ let with_version v t =
else raise (DecodingError ("expected version " ^ v))) else raise (DecodingError ("expected version " ^ v)))
(pair string_ t) (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} *) (** {2 Source of parsing} *)
module type SOURCE = sig module type SOURCE = sig

View file

@ -68,6 +68,9 @@ val with_version : string -> 'a t -> 'a t
(** Guards the values with a given version. Only values encoded with (** Guards the values with a given version. Only values encoded with
the same version will fit. *) 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} *) (** {2 Exceptions} *)
exception EOF exception EOF