Skip to content

Commit 87f4d74

Browse files
authored
[Docs][Belt] Categorize uncurried helpers into their dedicated section (rescript-lang#2628)
Addresses the feedback that the doc pages are hard to visually search. The uncurried APIs are basically expected to be there every time there's a higher-order function in the signature, so no need to even scroll down either.
1 parent 4d306ff commit 87f4d74

36 files changed

+906
-735
lines changed

jscomp/others/belt_HashMap.mli

+22-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
For example:
3232
{[
33-
type t = int
33+
type t = int
3434
module I0 =
3535
(val Belt.Id.hashableU
3636
~hash:(fun[\@bs] (a : t) -> a & 0xff_ff)
@@ -75,13 +75,13 @@ module Int = Belt_HashMapInt
7575

7676

7777
(** Specalized when key type is [string], more efficient
78-
than the gerneic type *)
78+
than the gerneic type *)
7979
module String = Belt_HashMapString
8080

8181

8282

8383

84-
type ('key,'value,'id) t
84+
type ('key,'value,'id) t
8585
(** The type of hash tables from type ['key] to type ['value]. *)
8686

8787
type ('a, 'id) id = ('a, 'id) Belt_Id.hashable
@@ -93,32 +93,30 @@ val make: hintSize:int -> id:('key, 'id) id -> ('key,'value,'id) t
9393
val clear: ('key, 'value, 'id ) t -> unit
9494
(** Empty a hash table. *)
9595

96-
val isEmpty: _ t -> bool
96+
val isEmpty: _ t -> bool
9797

9898
val set: ('key, 'value, 'id ) t -> 'key -> 'value -> unit
9999
(** [set tbl k v] if [k] does not exist,
100100
add the binding [k,v], otherwise, update the old value with the new
101101
[v]
102102
*)
103-
103+
104104
val copy: ('key, 'value, 'id ) t -> ('key, 'value, 'id ) t
105-
105+
106106
val get: ('key, 'value, 'id ) t -> 'key -> 'value option
107107

108-
108+
109109
val has: ('key, 'value, 'id ) t -> 'key -> bool
110110
(** [has tbl x] checks if [x] is bound in [tbl]. *)
111111

112112
val remove: ('key, 'value, 'id ) t -> 'key -> unit
113113

114-
val forEachU: ('key, 'value, 'id ) t -> ('key -> 'value -> unit [@bs]) -> unit
115114
val forEach: ('key, 'value, 'id ) t -> ('key -> 'value -> unit) -> unit
116115
(** [forEach tbl f] applies [f] to all bindings in table [tbl].
117116
[f] receives the key as first argument, and the associated value
118117
as second argument. Each binding is presented exactly once to [f].
119118
*)
120119

121-
val reduceU: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c [@bs]) -> 'c
122120
val reduce: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c) -> 'c
123121
(** [reduce tbl init f] computes
124122
[(f kN dN ... (f k1 d1 init)...)],
@@ -133,11 +131,10 @@ val reduce: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c) -> 'c
133131
*)
134132

135133

136-
val keepMapInPlaceU: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option [@bs]) -> unit
137134
val keepMapInPlace: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option ) -> unit
138135

139136

140-
val size: _ t -> int
137+
val size: _ t -> int
141138
(** [size tbl] returns the number of bindings in [tbl].
142139
It takes constant time. *)
143140

@@ -146,14 +143,23 @@ val size: _ t -> int
146143

147144

148145

149-
val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array
150-
val keysToArray: ('key, _, _) t -> 'key array
151-
val valuesToArray: (_,'value,_) t -> 'value array
152-
val fromArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
146+
val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array
147+
val keysToArray: ('key, _, _) t -> 'key array
148+
val valuesToArray: (_,'value,_) t -> 'value array
149+
val fromArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
153150
val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit
154151
val getBucketHistogram: _ t -> int array
155152
val logStats: _ t -> unit
156153

157-
val ofArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
154+
val ofArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
158155
[@@ocaml.deprecated "Use fromArray instead"]
159156

157+
158+
(** {1 Uncurried version} *)
159+
160+
161+
val forEachU: ('key, 'value, 'id ) t -> ('key -> 'value -> unit [@bs]) -> unit
162+
163+
val reduceU: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c [@bs]) -> 'c
164+
165+
val keepMapInPlaceU: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option [@bs]) -> unit

jscomp/others/belt_HashSet.mli

+14-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
For example:
3232
{[
33-
type t = int
33+
type t = int
3434
module I0 =
3535
(val Belt.Id.hashableU
3636
~hash:(fun[\@bs] (a : t) -> a & 0xff_ff)
@@ -74,7 +74,7 @@
7474
module Int = Belt_HashSetInt
7575

7676
(** Specalized when key type is [string], more efficient
77-
than the gerneic type *)
77+
than the gerneic type *)
7878
module String = Belt_HashSetString
7979

8080
(* TODO: add a poly module
@@ -83,8 +83,8 @@ module String = Belt_HashSetString
8383
- generic equal handles JS data structure
8484
- eq/hash consistent
8585
*)
86-
87-
type ('a, 'id) t
86+
87+
type ('a, 'id) t
8888

8989
(** The type of hash tables from type ['a] to type ['b]. *)
9090

@@ -102,27 +102,31 @@ val has: ('a, 'id) t -> 'a -> bool
102102

103103
val remove: ('a, 'id) t -> 'a -> unit
104104

105-
val forEachU: ('a, 'id) t -> ('a -> unit [@bs]) -> unit
106105
val forEach: ('a, 'id) t -> ('a -> unit) -> unit
107106
(** Order unspecified. *)
108107

109-
val reduceU: ('a, 'id) t -> 'c -> ('c -> 'a -> 'c [@bs]) -> 'c
110108
val reduce: ('a, 'id) t -> 'c -> ('c -> 'a -> 'c) -> 'c
111109
(** Order unspecified. *)
112110

113-
val size: ('a, 'id) t -> int
111+
val size: ('a, 'id) t -> int
114112

115113
val logStats: _ t -> unit
116114

117-
val toArray: ('a,'id) t -> 'a array
115+
val toArray: ('a,'id) t -> 'a array
118116

119-
val ofArray: 'a array -> id:('a,'id) id -> ('a,'id) t
117+
val ofArray: 'a array -> id:('a,'id) id -> ('a,'id) t
120118
[@@ocaml.deprecated "Use fromArray instead"]
121119

122-
val fromArray: 'a array -> id:('a,'id) id -> ('a,'id) t
120+
val fromArray: 'a array -> id:('a,'id) id -> ('a,'id) t
123121

124122
val mergeMany: ('a,'id) t -> 'a array -> unit
125123

126124
val getBucketHistogram: _ t -> int array
127125

128126

127+
(** {1 Uncurried version} *)
128+
129+
130+
val forEachU: ('a, 'id) t -> ('a -> unit [@bs]) -> unit
131+
132+
val reduceU: ('a, 'id) t -> 'c -> ('c -> 'a -> 'c [@bs]) -> 'c

jscomp/others/belt_Id.mli

+20-15
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ type ('key, 'id) comparable =
7474
mismatch if they use different comparison function
7575
*)
7676

77-
module MakeComparableU :
78-
functor (M : sig
79-
type t
80-
val cmp : t -> t -> int [@bs]
81-
end) ->
82-
Comparable with type t = M.t
83-
8477
module MakeComparable :
8578
functor (M : sig
8679
type t
@@ -118,14 +111,6 @@ type ('key, 'id) hashable =
118111
mismatch if they use different comparison function
119112
*)
120113

121-
module MakeHashableU :
122-
functor (M : sig
123-
type t
124-
val hash : t -> int [@bs]
125-
val eq : t -> t -> bool [@bs]
126-
end) ->
127-
Hashable with type t = M.t
128-
129114
module MakeHashable :
130115
functor (M : sig
131116
type t
@@ -153,3 +138,23 @@ external getHashInternal : ('a,'id) hash -> ('a -> int [@bs]) = "%identity"
153138
external getEqInternal : ('a, 'id) eq -> ('a -> 'a -> bool [@bs]) = "%identity"
154139
external getCmpInternal : ('a,'id) cmp -> ('a -> 'a -> int [@bs]) = "%identity"
155140
(**/**)
141+
142+
143+
(** {1 Uncurried version} *)
144+
145+
146+
module MakeComparableU :
147+
functor (M : sig
148+
type t
149+
val cmp : t -> t -> int [@bs]
150+
end) ->
151+
Comparable with type t = M.t
152+
153+
154+
module MakeHashableU :
155+
functor (M : sig
156+
type t
157+
val hash : t -> int [@bs]
158+
val eq : t -> t -> bool [@bs]
159+
end) ->
160+
Hashable with type t = M.t

0 commit comments

Comments
 (0)