mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
added a few helpers to Bij
This commit is contained in:
parent
44bd29766c
commit
ec41b0397d
2 changed files with 18 additions and 0 deletions
15
bij.ml
15
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
|
||||
|
|
|
|||
3
bij.mli
3
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue