22
22
* along with this program; if not, write to the Free Software
23
23
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24
24
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
+
25
38
type ('key, 'value, 'id) t
26
39
27
40
type ('key, 'id) cmp = ('key , 'id ) Belt_Id .cmp
@@ -60,44 +73,49 @@ val eq:
60
73
kcmp :('k , 'id ) cmp ->
61
74
veq :('a -> 'a -> bool ) ->
62
75
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. *)
67
79
68
80
val findFirstByU : ('k , 'v , 'id ) t -> ('k -> 'v -> bool [@ bs]) -> ('k * 'v ) option
69
81
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`.
72
84
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"))
76
94
```
77
95
*)
78
96
79
97
val forEachU : ('k , 'a , 'id ) t -> ('k -> 'a -> unit [@ bs]) -> unit
80
98
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. *)
85
103
86
104
val reduceU : ('k , 'a , 'id ) t -> 'b -> ('b -> 'k -> 'a -> 'b [@ bs]) -> 'b
87
105
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. *)
91
109
92
110
val everyU : ('k , 'a , 'id ) t -> ('k -> 'a -> bool [@ bs]) -> bool
93
111
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 *)
96
114
97
115
val someU : ('k , 'a , 'id ) t -> ('k -> 'a -> bool [@ bs]) -> bool
98
116
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 *)
101
119
102
120
val size : ('k , 'a , 'id ) t -> int
103
121
@@ -150,16 +168,13 @@ val getExn:
150
168
'a
151
169
152
170
val checkInvariantInternal : _ t -> unit
153
- (* *
154
- **raise** when invariant is not held
155
- *)
156
171
157
172
val remove :
158
173
('a , 'b , 'id ) t -> 'a ->
159
174
cmp :('a , 'id ) cmp ->
160
175
('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. *)
163
178
164
179
val removeMany :
165
180
('a , 'b , 'id ) t ->
@@ -171,9 +186,9 @@ val set:
171
186
('a , 'b , 'id ) t -> 'a -> 'b ->
172
187
cmp :('a , 'id ) cmp ->
173
188
('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. *)
177
192
178
193
val updateU :
179
194
('a , 'b , 'id ) t ->
@@ -198,10 +213,9 @@ val merge:
198
213
('a , 'c , 'id ) t ->
199
214
('a -> 'b option -> 'c option -> 'd option ) ->
200
215
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`
202
217
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`. *)
205
219
206
220
val mergeMany :
207
221
('a , 'b , 'id ) t ->
@@ -217,8 +231,8 @@ val keep:
217
231
('k , 'a , 'id ) t ->
218
232
('k -> 'a -> bool ) ->
219
233
('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`. *)
222
236
223
237
val partitionU :
224
238
('k , 'a , 'id ) t ->
@@ -228,33 +242,27 @@ val partition:
228
242
('k , 'a , 'id ) t ->
229
243
('k -> 'a -> bool ) ->
230
244
('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`. *)
236
248
237
249
val split :
238
250
('a , 'b , 'id ) t ->
239
251
'a ->
240
252
cmp :('a , 'id ) cmp ->
241
253
(('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`. *)
250
259
251
260
val mapU : ('k , 'a , 'id ) t -> ('a -> 'b [@ bs]) -> ('k ,'b,'id) t
252
261
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. *)
258
266
259
267
val mapWithKeyU : ('k , 'a , 'id ) t -> ('k -> 'a -> 'b [@ bs]) -> ('k , 'b , 'id ) t
260
268
val mapWithKey : ('k , 'a , 'id ) t -> ('k -> 'a -> 'b ) -> ('k , 'b , 'id ) t
0 commit comments