Skip to content

Commit f3e9224

Browse files
Sync docs for belt_MapInt.mli
1 parent 68db0d5 commit f3e9224

File tree

2 files changed

+110
-118
lines changed

2 files changed

+110
-118
lines changed

jscomp/others/belt_MapDict.mli

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
(** This module separates identity from data, it is a bit more verbose but
26+
slightly more efficient due to the fact that there is no need to pack
27+
identity and data back after each operation.
28+
29+
**_Advanced usage only_**
30+
*)
31+
32+
(* ```res prelude
33+
type t<'key, 'value, 'id>
34+
type cmp<'key, 'id> = Belt_Id.cmp<'key, 'id>
35+
```
36+
*)
37+
2538
type ('key, 'value, 'id) t
2639

2740
type ('key, 'id) cmp = ('key, 'id) Belt_Id.cmp
@@ -60,44 +73,49 @@ val eq:
6073
kcmp:('k, 'id) cmp ->
6174
veq:('a -> 'a -> bool) ->
6275
bool
63-
(** `eq m1 m2 cmp` tests whether the maps `m1` and `m2` are
64-
equal, that is, contain equal keys and associate them with
65-
equal data. `cmp` is the equality predicate used to compare
66-
the data associated with the keys. *)
76+
(** `eq(m1, m2, cmp)` tests whether the maps `m1` and `m2` are equal, that is,
77+
contain equal keys and associate them with equal data. `cmp` is the
78+
equality predicate used to compare the data associated with the keys. *)
6779

6880
val findFirstByU : ('k, 'v, 'id) t -> ('k -> 'v -> bool [@bs]) -> ('k * 'v) option
6981
val findFirstBy : ('k, 'v, 'id) t -> ('k -> 'v -> bool ) -> ('k * 'v) option
70-
(** `findFirstBy m p` uses funcion `f` to find the first key value pair
71-
to match predicate `p`.
82+
(** `findFirstBy(m, p)` uses function `f` to find the first key value pair to
83+
match predicate `p`.
7284
73-
```
74-
let s0 = fromArray ~id:(module IntCmp) [|4,"4";1,"1";2,"2,"3""|];;
75-
findFirstBy s0 (fun k v -> k = 4 ) = option (4, "4");;
85+
```res example
86+
module IntCmp = Belt.Id.MakeComparable({
87+
type t = int
88+
let cmp = Pervasives.compare
89+
})
90+
91+
let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp)
92+
93+
Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4"))
7694
```
7795
*)
7896

7997
val forEachU: ('k, 'a, 'id) t -> ('k -> 'a -> unit [@bs]) -> unit
8098
val forEach: ('k, 'a, 'id) t -> ('k -> 'a -> unit) -> unit
81-
(** `forEach m f` applies `f` to all bindings in map `m`.
82-
`f` receives the key as first argument, and the associated value
83-
as second argument. The bindings are passed to `f` in increasing
84-
order with respect to the ordering over the type of the keys. *)
99+
(** `forEach(m, f)` applies `f` to all bindings in map `m`. `f` receives the
100+
key as first argument, and the associated value as second argument. The
101+
bindings are passed to `f` in increasing order with respect to the ordering
102+
over the type of the keys. *)
85103

86104
val reduceU: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b [@bs]) -> 'b
87105
val reduce: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b) -> 'b
88-
(** `reduce m a f` computes `(f kN dN ... (f k1 d1 a)...)`,
89-
where `k1 ... kN` are the keys of all bindings in `m`
90-
(in increasing order), and `d1 ... dN` are the associated data. *)
106+
(** `reduce(m, a, f)` computes `f(kN, dN ... f(k1, d1, a)...)`, where `k1 ...
107+
kN` are the keys of all bindings in `m` (in increasing order), and `d1 ...
108+
dN` are the associated data. *)
91109

92110
val everyU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
93111
val every: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
94-
(** `every m p` checks if all the bindings of the map
95-
satisfy the predicate `p`. Order unspecified *)
112+
(** `every(m, p)` checks if all the bindings of the map satisfy the predicate
113+
`p`. Order unspecified *)
96114

97115
val someU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
98116
val some: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
99-
(** `some m p` checks if at least one binding of the map
100-
satisfy the predicate `p`. Order unspecified *)
117+
(** `some(m, p)` checks if at least one binding of the map satisfy the
118+
predicate `p`. Order unspecified *)
101119

102120
val size: ('k, 'a, 'id) t -> int
103121

@@ -150,16 +168,13 @@ val getExn:
150168
'a
151169

152170
val checkInvariantInternal: _ t -> unit
153-
(**
154-
**raise** when invariant is not held
155-
*)
156171

157172
val remove:
158173
('a, 'b, 'id) t -> 'a ->
159174
cmp:('a, 'id) cmp ->
160175
('a, 'b, 'id) t
161-
(** `remove m x` returns a map containing the same bindings as
162-
`m`, except for `x` which is unbound in the returned map. *)
176+
(** `remove(m, x)` returns a map containing the same bindings as `m`, except
177+
for `x` which is unbound in the returned map. *)
163178

164179
val removeMany:
165180
('a, 'b, 'id) t ->
@@ -171,9 +186,9 @@ val set:
171186
('a, 'b, 'id) t -> 'a -> 'b ->
172187
cmp:('a, 'id) cmp ->
173188
('a, 'b, 'id) t
174-
(** `set m x y` returns a map containing the same bindings as
175-
`m`, plus a binding of `x` to `y`. If `x` was already bound
176-
in `m`, its previous binding disappears. *)
189+
(** `set(m, x, y)` returns a map containing the same bindings as `m`, plus a
190+
binding of `x` to `y`. If `x` was already bound in `m`, its previous
191+
binding disappears. *)
177192

178193
val updateU:
179194
('a, 'b, 'id) t ->
@@ -198,10 +213,9 @@ val merge:
198213
('a, 'c, 'id) t ->
199214
('a -> 'b option -> 'c option -> 'd option) ->
200215
cmp:('a, 'id) cmp -> ('a, 'd, 'id) t
201-
(** `merge m1 m2 f` computes a map whose keys is a subset of keys of `m1`
216+
(** `merge(m1, m2, f)` computes a map whose keys is a subset of keys of `m1`
202217
and of `m2`. The presence of each such binding, and the corresponding
203-
value, is determined with the function `f`.
204-
*)
218+
value, is determined with the function `f`. *)
205219

206220
val mergeMany:
207221
('a, 'b, 'id) t ->
@@ -217,8 +231,8 @@ val keep:
217231
('k, 'a, 'id) t ->
218232
('k -> 'a -> bool) ->
219233
('k, 'a, 'id) t
220-
(** `keep m p` returns the map with all the bindings in `m`
221-
that satisfy predicate `p`. *)
234+
(** `keep(m, p)` returns the map with all the bindings in `m` that satisfy
235+
predicate `p`. *)
222236

223237
val partitionU:
224238
('k, 'a, 'id) t ->
@@ -228,33 +242,27 @@ val partition:
228242
('k, 'a, 'id) t ->
229243
('k -> 'a -> bool) ->
230244
('k, 'a, 'id) t * ('k, 'a, 'id) t
231-
(** `partition m p` returns a pair of maps `(m1, m2)`, where
232-
`m1` contains all the bindings of `s` that satisfy the
233-
predicate `p`, and `m2` is the map with all the bindings of
234-
`s` that do not satisfy `p`.
235-
*)
245+
(** `partition(m, p)` returns a pair of maps `(m1, m2)`, where `m1` contains
246+
all the bindings of `s` that satisfy the predicate `p`, and `m2` is the map
247+
with all the bindings of `s` that do not satisfy `p`. *)
236248

237249
val split:
238250
('a, 'b, 'id) t ->
239251
'a ->
240252
cmp:('a, 'id) cmp ->
241253
(('a,'b,'id) t * ('a, 'b, 'id) t) * 'b option
242-
(** `split x m` returns a triple `(l, data, r)`, where
243-
`l` is the map with all the bindings of `m` whose key
244-
is strictly less than `x`;
245-
`r` is the map with all the bindings of `m` whose key
246-
is strictly greater than `x`;
247-
`data` is `None` if `m` contains no binding for `x`,
248-
or `Some v` if `m` binds `v` to `x`.
249-
*)
254+
(** `split(x, m)` returns a triple `(l, data, r)`, where `l` is the map with
255+
all the bindings of `m` whose key is strictly less than `x`; `r` is the map
256+
with all the bindings of `m` whose key is strictly greater than `x`; `data`
257+
is `None` if `m` contains no binding for `x`, or `Some(v)` if `m` binds `v`
258+
to `x`. *)
250259

251260
val mapU: ('k, 'a, 'id) t -> ('a -> 'b [@bs]) -> ('k ,'b,'id) t
252261
val map: ('k, 'a, 'id) t -> ('a -> 'b) -> ('k ,'b,'id) t
253-
(** `map m f` returns a map with same domain as `m`, where the
254-
associated value `a` of all bindings of `m` has been
255-
replaced by the result of the application of `f` to `a`.
256-
The bindings are passed to `f` in increasing order
257-
with respect to the ordering over the type of the keys. *)
262+
(** `map(m, f)` returns a map with same domain as `m`, where the associated
263+
value `a` of all bindings of `m` has been replaced by the result of the
264+
application of `f` to `a`. The bindings are passed to `f` in increasing
265+
order with respect to the ordering over the type of the keys. *)
258266

259267
val mapWithKeyU: ('k, 'a, 'id) t -> ('k -> 'a -> 'b [@bs]) -> ('k, 'b, 'id) t
260268
val mapWithKey: ('k, 'a, 'id) t -> ('k -> 'a -> 'b) -> ('k, 'b, 'id) t

jscomp/others/belt_MapInt.mli

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
(** Specalized when key type is `int`, more efficient than the generic type,
2+
its compare behavior is fixed using the built-in comparison. *)
3+
4+
(* ```res prelude
5+
type key = int
6+
type t<'value>
7+
```
8+
*)
9+
110
# 4 "others/map.cppo.mli"
211
type key = int
312
# 8 "others/map.cppo.mli"
@@ -15,50 +24,43 @@ val cmp: 'v t -> 'v t -> ('v -> 'v -> int) -> int
1524

1625
val eqU: 'v t -> 'v t -> ('v -> 'v -> bool [@bs]) -> bool
1726
val eq: 'v t -> 'v t -> ('v -> 'v -> bool) -> bool
18-
(**
19-
`eq m1 m2` tests whether the maps `m1` and `m2` are
20-
equal, that is, contain equal keys and associate them with
21-
equal data.
22-
*)
27+
(** `eq(m1,m2)` tests whether the maps `m1` and `m2` are equal, that is,
28+
contain equal keys and associate them with equal data. *)
2329

2430
val findFirstByU : 'v t -> (key -> 'v -> bool [@bs]) -> (key * 'v) option
2531
val findFirstBy : 'v t -> (key -> 'v -> bool) -> (key * 'v) option
26-
(**
27-
`findFirstBy m p` uses funcion `f` to find the first key value pair
28-
to match predicate `p`.
29-
30-
```
31-
let s0 = fromArray ~id:(module IntCmp) [|4,"4";1,"1";2,"2,"3""|];;
32-
findFirstBy s0 (fun k v -> k = 4 ) = option (4, "4");;
33-
```
32+
(** `findFirstBy(m, p)` uses function `f` to find the first key value pair to
33+
match predicate `p`.
34+
35+
```res example
36+
let s0 = Belt.Map.Int.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")])
37+
38+
Belt.Map.Int.findFirstBy(s0, (k, v) => k == 4) == Some((4, "4"))
39+
```
3440
*)
3541

3642
val forEachU: 'v t -> (key -> 'v -> unit [@bs]) -> unit
3743
val forEach: 'v t -> (key -> 'v -> unit) -> unit
38-
(**
39-
`forEach m f` applies `f` to all bindings in map `m`.
40-
`f` receives the key as first argument, and the associated value
41-
as second argument. The bindings are passed to `f` in increasing
42-
order with respect to the ordering over the type of the keys.
43-
*)
44+
(** `forEach(m, f)` applies `f` to all bindings in map `m`. `f` receives the
45+
key as first argument, and the associated value as second argument. The
46+
bindings are passed to `f` in increasing order with respect to the ordering
47+
over the type of the keys. *)
4448

4549
val reduceU: 'v t -> 'v2 -> ('v2 -> key -> 'v -> 'v2 [@bs]) -> 'v2
4650
val reduce: 'v t -> 'v2 -> ('v2 -> key -> 'v -> 'v2) -> 'v2
47-
(**
48-
`reduce m a f` computes `(f kN dN ... (f k1 d1 a)...)`,
49-
where `k1 ... kN` are the keys of all bindings in `m`
50-
(in increasing order), and `d1 ... dN` are the associated data.
51-
*)
51+
(** `reduce(m, a, f)` computes `f(kN, dN, ... f(k1, d1, a)...)`, where `k1 ...
52+
kN` are the keys of all bindings in `m` (in increasing order), and `d1 ...
53+
dN` are the associated data. *)
5254

5355
val everyU: 'v t -> (key -> 'v -> bool [@bs]) -> bool
5456
val every: 'v t -> (key -> 'v -> bool) -> bool
55-
(** `every m p` checks if all the bindings of the map
56-
satisfy the predicate `p`. Order unspecified *)
57+
(** `every(m, p)` checks if all the bindings of the map satisfy the predicate
58+
`p`. Order unspecified *)
5759

5860
val someU: 'v t -> (key -> 'v -> bool [@bs]) -> bool
5961
val some: 'v t -> (key -> 'v -> bool) -> bool
60-
(** `some m p` checks if at least one binding of the map
61-
satisfy the predicate `p`. Order unspecified *)
62+
(** `some(m, p)` checks if at least one binding of the map satisfy the
63+
predicate `p`. Order unspecified *)
6264

6365
val size: 'v t -> int
6466

@@ -99,22 +101,18 @@ val getWithDefault: 'v t -> key -> 'v -> 'v
99101
val getExn: 'v t -> key -> 'v
100102

101103
val checkInvariantInternal: _ t -> unit
102-
(**
103-
**raise** when invariant is not held
104-
*)
104+
(** **raise** when invariant is not held. *)
105105

106106
val remove: 'v t -> key -> 'v t
107-
(** `remove m x` returns a map containing the same bindings as
108-
`m`, except for `x` which is unbound in the returned map. *)
107+
(** `remove(m, x)` returns a map containing the same bindings as `m`, except
108+
for `x` which is unbound in the returned map. *)
109109

110110
val removeMany: 'v t -> key array -> 'v t
111111

112112
val set: 'v t -> key -> 'v -> 'v t
113-
(**
114-
`set m x y` returns a map containing the same bindings as
115-
`m`, plus a binding of `x` to `y`. If `x` was already bound
116-
in `m`, its previous binding disappears.
117-
*)
113+
(** `set(m, x, y)` returns a map containing the same bindings as `m`, plus a
114+
binding of `x` to `y`. If `x` was already bound in `m`, its previous
115+
binding disappears. *)
118116

119117
val updateU: 'v t -> key -> ('v option -> 'v option [@bs]) -> 'v t
120118
val update: 'v t -> key -> ('v option -> 'v option) -> 'v t
@@ -127,11 +125,9 @@ val merge:
127125
'v t -> 'v2 t ->
128126
(key -> 'v option -> 'v2 option -> 'c option) ->
129127
'c t
130-
(**
131-
`merge m1 m2 f` computes a map whose keys is a subset of keys of `m1`
132-
and of `m2`. The presence of each such binding, and the corresponding
133-
value, is determined with the function `f`.
134-
*)
128+
(** `merge(m1, m2, f)` computes a map whose keys is a subset of keys of `m1`
129+
and of `m2`. The presence of each such binding, and the corresponding
130+
value, is determined with the function `f`. *)
135131

136132
val mergeMany: 'v t -> (key * 'v) array -> 'v t
137133

@@ -144,8 +140,6 @@ val keep:
144140
'v t ->
145141
(key -> 'v -> bool) ->
146142
'v t
147-
(** `keep m p` returns the map with all the bindings in `m`
148-
that satisfy predicate `p`. *)
149143

150144
val partitionU:
151145
'v t ->
@@ -155,33 +149,23 @@ val partition:
155149
'v t ->
156150
(key -> 'v -> bool) ->
157151
'v t * 'v t
158-
(**
159-
`partition m p` returns a pair of maps `(m1, m2)`, where
160-
`m1` contains all the bindings of `s` that satisfy the
161-
predicate `p`, and `m2` is the map with all the bindings of
162-
`s` that do not satisfy `p`.
163-
*)
152+
(** `partition(m, p)` returns a pair of maps `(m1, m2)`, where `m1` contains
153+
all the bindings of `s` that satisfy the predicate `p`, and `m2` is the map
154+
with all the bindings of `s` that do not satisfy `p`. *)
164155

165156
val split: key -> 'v t -> 'v t * 'v option * 'v t
166-
(**
167-
`split x m` returns a triple `(l, data, r)`, where
168-
`l` is the map with all the bindings of `m` whose key
169-
is strictly less than `x`;
170-
`r` is the map with all the bindings of `m` whose key
171-
is strictly greater than `x`;
172-
`data` is `None` if `m` contains no binding for `x`,
173-
or `Some v` if `m` binds `v` to `x`.
174-
*)
157+
(** `split(x, m)` returns a triple `(l, data, r)`, where `l` is the map with
158+
all the bindings of `m` whose key is strictly less than `x`; `r` is the map
159+
with all the bindings of `m` whose key is strictly greater than `x`; `data`
160+
is `None` if m contains no binding for `x`, or `Some(v)` if `m` binds `v`
161+
to `x`. *)
175162

176163
val mapU: 'v t -> ('v -> 'v2 [@bs]) -> 'v2 t
177164
val map: 'v t -> ('v -> 'v2) -> 'v2 t
178-
(**
179-
`map m f` returns a map with same domain as `m`, where the
180-
associated value `a` of all bindings of `m` has been
181-
replaced by the result of the application of `f` to `a`.
182-
The bindings are passed to `f` in increasing order
183-
with respect to the ordering over the type of the keys.
184-
*)
165+
(** `map(m, f)` returns a map with same domain as `m`, where the associated
166+
value `a` of all bindings of `m` has been replaced by the result of the
167+
application of `f` to `a`. The bindings are passed to `f` in increasing
168+
order with respect to the ordering over the type of the keys. *)
185169

186170
val mapWithKeyU: 'v t -> (key -> 'v -> 'v2 [@bs]) -> 'v2 t
187171
val mapWithKey: 'v t -> (key -> 'v -> 'v2) -> 'v2 t

0 commit comments

Comments
 (0)