1Map.S(3)                         OCaml library                        Map.S(3)
2
3
4

NAME

6       Map.S - Output signature of the functor Map.Make.
7

Module type

9       Module type   Map.S
10

Documentation

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 update : key -> ('a option -> 'a option) -> 'a t -> 'a t
71
72
73       update x f m returns a map containing the same bindings as m  ,  except
74       for  the  binding  of  x  .  Depending  on  the value of y where y is f
75       (find_opt x m) , the binding of x is added, removed or updated. If y is
76       None  ,  the binding is removed if it exists; otherwise, if y is Some z
77       then x is associated to z in the resulting map.  If x was already bound
78       in m to a value that is physically equal to z , m is returned unchanged
79       (the result of the function is then physically equal 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
102       returned 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 is a subset of keys of m1 and
116       of m2 . The presence of each such binding, and the corresponding value,
117       is  determined  with  the function f .  In terms of the find_opt opera‐
118       tion, we have find_opt x (merge f m1 m2) = f (find_opt x m1)  (find_opt
119       x m2) for any key x , provided that f 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 is the union of keys of m1 and
130       of m2 .  When the same binding is defined in both arguments, the  func‐
131       tion  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 a computes (f kN dN ... (f k1 d1 a)...)  , where k1 ... kN are
182       the  keys of all bindings in m (in increasing order), and d1 ... dN are
183       the associated data.
184
185
186
187       val for_all : (key -> 'a -> bool) -> 'a t -> bool
188
189
190       for_all p m checks if all the bindings of the map satisfy the predicate
191       p .
192
193
194       Since 3.12.0
195
196
197
198       val exists : (key -> 'a -> bool) -> 'a t -> bool
199
200
201       exists  p  m  checks  if  at least one binding of the map satisfies the
202       predicate p .
203
204
205       Since 3.12.0
206
207
208
209       val filter : (key -> 'a -> bool) -> 'a t -> 'a t
210
211
212       filter p m returns the map with all the  bindings  in  m  that  satisfy
213       predicate  p  .  If  p  satisfies  every  binding  in m , m is returned
214       unchanged (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 partition : (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
226
227
228       partition p m returns a pair of maps (m1, m2) , where m1  contains  all
229       the bindings of s that satisfy the predicate p , and m2 is the map with
230       all the bindings of s that do not satisfy p .
231
232
233       Since 3.12.0
234
235
236
237       val cardinal : 'a t -> int
238
239       Return the number of bindings of a map.
240
241
242       Since 3.12.0
243
244
245
246       val bindings : 'a t -> (key * 'a) list
247
248       Return the list of all bindings of the given map.  The returned list is
249       sorted  in  increasing  order  of  keys  with  respect  to the ordering
250       Ord.compare , where Ord is the argument given to Map.Make .
251
252
253       Since 3.12.0
254
255
256
257       val min_binding : 'a t -> key * 'a
258
259       Return the binding with the smallest key in a given map  (with  respect
260       to the Ord.compare ordering), or raise Not_found if the map is empty.
261
262
263       Since 3.12.0
264
265
266
267       val min_binding_opt : 'a t -> (key * 'a) option
268
269       Return the binding with the smallest key in the given map (with respect
270       to the Ord.compare ordering), or None if the map is empty.
271
272
273       Since 4.05
274
275
276
277       val max_binding : 'a t -> key * 'a
278
279       Same as Map.S.min_binding , but returns the binding  with  the  largest
280       key in the given map.
281
282
283       Since 3.12.0
284
285
286
287       val max_binding_opt : 'a t -> (key * 'a) option
288
289       Same  as  Map.S.min_binding_opt  ,  but  returns  the  binding with the
290       largest key in the given map.
291
292
293       Since 4.05
294
295
296
297       val choose : 'a t -> key * 'a
298
299       Return one binding of the given map, or raise Not_found if the  map  is
300       empty.  Which binding is chosen is unspecified, but equal bindings will
301       be chosen for equal maps.
302
303
304       Since 3.12.0
305
306
307
308       val choose_opt : 'a t -> (key * 'a) option
309
310       Return one binding of the given map, or None if the map is empty. Which
311       binding is chosen is unspecified, but equal bindings will be chosen for
312       equal maps.
313
314
315       Since 4.05
316
317
318
319       val split : key -> 'a t -> 'a t * 'a option * 'a t
320
321
322       split x m returns a triple (l, data, r) , where l is the map  with  all
323       the bindings of m whose key is strictly less than x ; r is the map with
324       all the bindings of m whose key is strictly greater than x  ;  data  is
325       None if m contains no binding for x , or Some v if m binds v to x .
326
327
328       Since 3.12.0
329
330
331
332       val find : key -> 'a t -> 'a
333
334
335       find x m returns the current binding of x in m , or raises Not_found if
336       no such binding exists.
337
338
339
340       val find_opt : key -> 'a t -> 'a option
341
342
343       find_opt x m returns Some v if the current binding of x in m is v ,  or
344       None if no such binding exists.
345
346
347       Since 4.05
348
349
350
351       val find_first : (key -> bool) -> 'a t -> key * 'a
352
353
354       find_first  f  m  ,  where  f  is  a monotonically increasing function,
355       returns the binding of m with the lowest key k  such  that  f  k  ,  or
356       raises Not_found if no such key exists.
357
358       For  example,  find_first (fun k -> Ord.compare k x >= 0) m will return
359       the first binding k, v of m where Ord.compare k x >= 0 (intuitively:  k
360       >= x ), or raise Not_found if x is greater than any element of m .
361
362
363       Since 4.05
364
365
366
367       val find_first_opt : (key -> bool) -> 'a t -> (key * 'a) option
368
369
370       find_first_opt  f  m  , where f is a monotonically increasing function,
371       returns an option containing the binding of m with  the  lowest  key  k
372       such that f k , or None if no such key exists.
373
374
375       Since 4.05
376
377
378
379       val find_last : (key -> bool) -> 'a t -> key * 'a
380
381
382       find_last f m , where f is a monotonically decreasing function, returns
383       the binding of m with the highest key k such  that  f  k  ,  or  raises
384       Not_found if no such key exists.
385
386
387       Since 4.05
388
389
390
391       val find_last_opt : (key -> bool) -> 'a t -> (key * 'a) option
392
393
394       find_last_opt  f  m  ,  where f is a monotonically decreasing function,
395       returns an option containing the binding of m with the  highest  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 map : ('a -> 'b) -> 'a t -> 'b t
404
405
406       map  f  m  returns  a  map with same domain as m , where the associated
407       value a of all bindings of m has been replaced by  the  result  of  the
408       application  of  f  to  a .  The bindings are passed to f in increasing
409       order with respect to the ordering over the type of the keys.
410
411
412
413       val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
414
415       Same as Map.S.map , but the function receives as arguments both the key
416       and the associated value for each binding of the map.
417
418
419
420
421   Iterators
422       val to_seq : 'a t -> (key * 'a) Seq.t
423
424       Iterate on the whole map, in ascending order of keys
425
426
427       Since 4.07
428
429
430
431       val to_seq_from : key -> 'a t -> (key * 'a) Seq.t
432
433
434       to_seq_from  k m iterates on a subset of the bindings of m , in ascend‐
435       ing order of keys, from key k or above.
436
437
438       Since 4.07
439
440
441
442       val add_seq : (key * 'a) Seq.t -> 'a t -> 'a t
443
444       Add the given bindings to the map, in order.
445
446
447       Since 4.07
448
449
450
451       val of_seq : (key * 'a) Seq.t -> 'a t
452
453       Build a map from the given bindings
454
455
456       Since 4.07
457
458
459
460
461
462OCamldoc                          2019-07-30                          Map.S(3)
Impressum