1Misc.Stdlib.String.Map(3)        OCaml library       Misc.Stdlib.String.Map(3)
2
3
4

NAME

6       Misc.Stdlib.String.Map - no description
7

Module

9       Module   Misc.Stdlib.String.Map
10

Documentation

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