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