Skip to content

Commit c38c36c

Browse files
committed
add atd wrapper for hash tables
1 parent 211f96e commit c38c36c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/common.atd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
type 'v map_as_object =
22
(string * 'v) list <json repr="object">
33
wrap <ocaml module="Common.StringMap" t="'v Common.StringMap.t">
4+
5+
type 'v table_as_object =
6+
(string * 'v) list <json repr="object">
7+
wrap <ocaml module="Common.Stringtbl" t="'v Common.Stringtbl.t">

lib/common.ml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
open Base
2-
open Devkit
32

43
module StringMap = struct
54
type 'a t = 'a Map.M(String).t
@@ -11,13 +10,31 @@ module StringMap = struct
1110
let unwrap = to_list
1211
end
1312

13+
module Stringtbl = struct
14+
include Hashtbl
15+
16+
type 'a t = 'a Hashtbl.M(String).t
17+
18+
let empty () = Hashtbl.create (module String)
19+
20+
let to_list (l : 'a t) : (string * 'a) list = Hashtbl.to_alist l
21+
22+
let of_list (m : (string * 'a) list) : 'a t = Hashtbl.of_alist_exn (module String) m
23+
24+
let wrap = of_list
25+
26+
let unwrap = to_list
27+
end
28+
1429
module Re2 = struct
1530
include Re2
1631

1732
let wrap s = create_exn s
1833
let unwrap = Re2.to_string
1934
end
2035

36+
open Devkit
37+
2138
let fmt_error fmt = Printf.ksprintf (fun s -> Error s) fmt
2239

2340
let first_line s =

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(library
22
(name lib)
33
(libraries atdgen atdgen-runtime base base64 base.caml biniou cstruct curl curl.lwt
4-
devkit devkit.core extlib hex lwt lwt.unix nocrypto omd re2 stdio uri
4+
devkit devkit.core extlib hex lwt lwt.unix nocrypto omd re2 sexplib0 stdio uri
55
yojson)
66
(preprocess
77
(pps lwt_ppx)))

0 commit comments

Comments
 (0)