1Map.S(3) OCamldoc Map.S(3)
2
3
4
6 Map.S - Output signature of the functor Map.Make.
7
9 Module type Map.S
10
12 Module type S
13 = sig end
14
15
16 Output signature of the functor Map.Make .
17
18
19
20
21
22 type key
23
24
25 The type of the map keys.
26
27
28 type +'a t
29
30
31 The type of maps from type key to type 'a .
32
33
34
35 val empty : 'a t
36
37 The empty map.
38
39
40
41 val is_empty : 'a t -> bool
42
43 Test whether a map is empty or not.
44
45
46
47 val mem : key -> 'a t -> bool
48
49
50 mem x m returns true if m contains a binding for x , and false other‐
51 wise.
52
53
54
55 val add : key -> 'a -> 'a t -> 'a t
56
57
58 add x y m returns a map containing the same bindings as m , plus a
59 binding of x to y . If x was already bound in m to a value that is
60 physically equal to y , m is returned unchanged (the result of the
61 function is then physically equal to m ). Otherwise, the previous bind‐
62 ing of x in m disappears.
63
64
65 Before4.03 Physical equality was not ensured.
66
67
68
69
70 val singleton : key -> 'a -> 'a t
71
72
73 singleton x y returns the one-element map that contains a binding y for
74 x .
75
76
77 Since 3.12.0
78
79
80
81 val remove : key -> 'a t -> 'a t
82
83
84 remove x m returns a map containing the same bindings as m , except for
85 x which is unbound in the returned map. If x was not in m , m is
86 returned unchanged (the result of the function is then physically equal
87 to m ).
88
89
90 Before4.03 Physical equality was not ensured.
91
92
93
94
95 val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b
96 t -> 'c t
97
98
99 merge f m1 m2 computes a map whose keys is a subset of keys of m1 and
100 of m2 . The presence of each such binding, and the corresponding value,
101 is determined with the function f . In terms of the find_opt opera‐
102 tion, we have find_opt x (merge f m1 m2) = f (find_opt x m1) (find_opt
103 x m2) for any key x , provided that f None None = None .
104
105
106 Since 3.12.0
107
108
109
110 val union : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t
111
112
113 union f m1 m2 computes a map whose keys is the union of keys of m1 and
114 of m2 . When the same binding is defined in both arguments, the func‐
115 tion f is used to combine them. This is a special case of merge :
116 union f m1 m2 is equivalent to merge f' m1 m2 , where
117
118 - f' None None = None
119
120
121 - f' (Some v) None = Some v
122
123
124 - f' None (Some v) = Some v
125
126
127 - f' (Some v1) (Some v2) = f v1 v2
128
129
130
131
132 Since 4.03.0
133
134
135
136 val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
137
138 Total ordering between maps. The first argument is a total ordering
139 used to compare data associated with equal keys in the two maps.
140
141
142
143 val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
144
145
146 equal cmp m1 m2 tests whether the maps m1 and m2 are equal, that is,
147 contain equal keys and associate them with equal data. cmp is the
148 equality predicate used to compare the data associated with the keys.
149
150
151
152 val iter : (key -> 'a -> unit) -> 'a t -> unit
153
154
155 iter f m applies f to all bindings in map m . f receives the key as
156 first argument, and the associated value as second argument. The bind‐
157 ings are passed to f in increasing order with respect to the ordering
158 over the type of the keys.
159
160
161
162 val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
163
164
165 fold f m a computes (f kN dN ... (f k1 d1 a)...) , where k1 ... kN are
166 the keys of all bindings in m (in increasing order), and d1 ... dN are
167 the associated data.
168
169
170
171 val for_all : (key -> 'a -> bool) -> 'a t -> bool
172
173
174 for_all p m checks if all the bindings of the map satisfy the predicate
175 p .
176
177
178 Since 3.12.0
179
180
181
182 val exists : (key -> 'a -> bool) -> 'a t -> bool
183
184
185 exists p m checks if at least one binding of the map satisfies the
186 predicate p .
187
188
189 Since 3.12.0
190
191
192
193 val filter : (key -> 'a -> bool) -> 'a t -> 'a t
194
195
196 filter p m returns the map with all the bindings in m that satisfy
197 predicate p . If p satisfies every binding in m , m is returned
198 unchanged (the result of the function is then physically equal to m )
199
200
201 Before4.03 Physical equality was not ensured.
202
203
204
205 Since 3.12.0
206
207
208
209 val partition : (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
210
211
212 partition p m returns a pair of maps (m1, m2) , where m1 contains all
213 the bindings of s that satisfy the predicate p , and m2 is the map with
214 all the bindings of s that do not satisfy p .
215
216
217 Since 3.12.0
218
219
220
221 val cardinal : 'a t -> int
222
223 Return the number of bindings of a map.
224
225
226 Since 3.12.0
227
228
229
230 val bindings : 'a t -> (key * 'a) list
231
232 Return the list of all bindings of the given map. The returned list is
233 sorted in increasing order with respect to the ordering Ord.compare ,
234 where Ord is the argument given to Map.Make .
235
236
237 Since 3.12.0
238
239
240
241 val min_binding : 'a t -> key * 'a
242
243 Return the smallest binding of the given map (with respect to the
244 Ord.compare ordering), or raise Not_found if the map is empty.
245
246
247 Since 3.12.0
248
249
250
251 val min_binding_opt : 'a t -> (key * 'a) option
252
253 Return the smallest binding of the given map (with respect to the
254 Ord.compare ordering), or None if the map is empty.
255
256
257 Since 4.05
258
259
260
261 val max_binding : 'a t -> key * 'a
262
263 Same as Map.S.min_binding , but returns the largest binding of the
264 given map.
265
266
267 Since 3.12.0
268
269
270
271 val max_binding_opt : 'a t -> (key * 'a) option
272
273 Same as Map.S.min_binding_opt , but returns the largest binding of the
274 given map.
275
276
277 Since 4.05
278
279
280
281 val choose : 'a t -> key * 'a
282
283 Return one binding of the given map, or raise Not_found if the map is
284 empty. Which binding is chosen is unspecified, but equal bindings will
285 be chosen for equal maps.
286
287
288 Since 3.12.0
289
290
291
292 val choose_opt : 'a t -> (key * 'a) option
293
294 Return one binding of the given map, or None if the map is empty. Which
295 binding is chosen is unspecified, but equal bindings will be chosen for
296 equal maps.
297
298
299 Since 4.05
300
301
302
303 val split : key -> 'a t -> 'a t * 'a option * 'a t
304
305
306 split x m returns a triple (l, data, r) , where l is the map with all
307 the bindings of m whose key is strictly less than x ; r is the map with
308 all the bindings of m whose key is strictly greater than x ; data is
309 None if m contains no binding for x , or Some v if m binds v to x .
310
311
312 Since 3.12.0
313
314
315
316 val find : key -> 'a t -> 'a
317
318
319 find x m returns the current binding of x in m , or raises Not_found if
320 no such binding exists.
321
322
323
324 val find_opt : key -> 'a t -> 'a option
325
326
327 find_opt x m returns Some v if the current binding of x in m is v , or
328 None if no such binding exists.
329
330
331 Since 4.05
332
333
334
335 val find_first : (key -> bool) -> 'a t -> key * 'a
336
337
338 find_first f m , where f is a monotonically increasing function,
339 returns the binding of m with the lowest key k such that f k , or
340 raises Not_found if no such key exists.
341
342 For example, find_first (fun k -> Ord.compare k x >= 0) m will return
343 the first binding k, v of m where Ord.compare k x >= 0 (intuitively: k
344 >= x ), or raise Not_found if x is greater than any element of m .
345
346
347 Since 4.05
348
349
350
351 val find_first_opt : (key -> bool) -> 'a t -> (key * 'a) option
352
353
354 find_first_opt f m , where f is a monotonically increasing function,
355 returns an option containing the binding of m with the lowest key k
356 such that f k , or None if no such key exists.
357
358
359 Since 4.05
360
361
362
363 val find_last : (key -> bool) -> 'a t -> key * 'a
364
365
366 find_last f m , where f is a monotonically decreasing function, returns
367 the binding of m with the highest key k such that f k , or raises
368 Not_found if no such key exists.
369
370
371 Since 4.05
372
373
374
375 val find_last_opt : (key -> bool) -> 'a t -> (key * 'a) option
376
377
378 find_last_opt f m , where f is a monotonically decreasing function,
379 returns an option containing the binding of m with the highest key k
380 such that f k , or None if no such key exists.
381
382
383 Since 4.05
384
385
386
387 val map : ('a -> 'b) -> 'a t -> 'b t
388
389
390 map f m returns a map with same domain as m , where the associated
391 value a of all bindings of m has been replaced by the result of the
392 application of f to a . The bindings are passed to f in increasing
393 order with respect to the ordering over the type of the keys.
394
395
396
397 val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
398
399 Same as Map.S.map , but the function receives as arguments both the key
400 and the associated value for each binding of the map.
401
402
403
404
405
4062018-04-14 source: Map.S(3)