module type S = sig
.. end
val empty : ('a, 'b) T.t
the empty map
val singleton : 'a T.key -> 'b -> ('a, 'b) T.t
map with one key, data pair
val is_empty : ('a, 'b) T.t -> bool
Test whether a map is empty or not.
val cardinal : ('a, 'b) T.t -> int
cardinal map
Returns number of elements in map
.
val add : key:'a T.key -> data:'b -> ('a, 'b) T.t -> ('a, 'b) T.t
returns a new map with the specified new binding;
if the key was already bound, its previous binding disappears.
val find_exn : ('a, 'b) T.t -> 'a T.key -> 'b
returns the value bound to the given key, raising Not_found
if none
such exists
val find : ('a, 'b) T.t -> 'a T.key -> 'b option
val remove : ('a, 'b) T.t -> 'a T.key -> ('a, 'b) T.t
returns a new map with any binding for the key in question removed
val mem : ('a, 'b) T.t -> 'a T.key -> bool
mem key map
tests whether map
contains a binding for key
val iter : f:(key:'a T.key -> data:'b -> unit) -> ('a, 'b) T.t -> unit
iterator for map
val map : f:('a -> 'b) -> ('c, 'a) T.t -> ('c, 'b) T.t
returns new map with bound values replaced by f applied to the bound values
val mapi : f:(key:'a T.key -> data:'b -> 'c) -> ('a, 'b) T.t -> ('a, 'c) T.t
like map
, but function takes both key and data as arguments
val fold : f:(key:'a T.key -> data:'b -> 'c -> 'c) -> ('a, 'b) T.t -> init:'c -> 'c
folds over keys and data in map
val filter : f:(key:'a T.key -> data:'b -> bool) -> ('a, 'b) T.t -> ('a, 'b) T.t
filter for map
val filter_map : f:('a -> 'b option) -> ('c, 'a) T.t -> ('c, 'b) T.t
returns new map with bound values filtered by f applied to the bound
values
val filter_mapi : f:(key:'a T.key -> data:'b -> 'c option) -> ('a, 'b) T.t -> ('a, 'c) T.t
like filter_map
, but function takes both key and data as arguments
val compare : ('a -> 'a -> int) -> ('b, 'a) T.t -> ('b, 'a) T.t -> int
Total ordering between maps. The first argument is a total ordering
used to compare data associated with equal keys in the two maps.
val equal : ('a -> 'a -> bool) -> ('b, 'a) T.t -> ('b, 'a) T.t -> bool
equal cmp m1 m2
tests whether the maps m1
and m2
are
equal, that is, contain equal keys and associate them with
equal data. cmp
is the equality predicate used to compare
the data associated with the keys.
val keys : ('a, 'b) T.t -> 'a T.key list
returns list of keys in map
val has_key : ('a, 'b) T.t -> 'a T.key -> bool
equivalent to mem
val data : ('a, 'b) T.t -> 'b list
returns list of data in map
val of_alist : ('a T.key * 'b) list -> [ `Duplicate_key of 'a T.key | `Ok of ('a, 'b) T.t ]
creates map from association list with unique keys
val of_alist_exn : ('a T.key * 'b) list -> ('a, 'b) T.t
creates map from association list with unique keys. Raises Failure if
duplicate 'a keys are found.
val of_alist_multi : ('a T.key * 'b) list -> ('a, 'b list) T.t
creates map from association list with possibly repeated keys.
val to_alist : ('a, 'b) T.t -> ('a T.key * 'b) list
creates association list from map. No guarantee about order.
Additional operations on maps
val combine_alist : ('a T.key * 'b) list -> init:'c -> f:('b -> 'c -> 'c) -> ('a, 'c) T.t
combines an association list into a map, folding together the bound
values (for experts only)
val merge : f:(key:'a T.key -> 'b option -> 'c option -> 'd option) ->
('a, 'b) T.t -> ('a, 'c) T.t -> ('a, 'd) T.t
merges two maps
val min_elt : ('a, 'b) T.t -> ('a T.key * 'b) option
min_elt map
Returns Some (key, data)
pair corresponding to the
minimum key in map
, None if empty.
val min_elt_exn : ('a, 'b) T.t -> 'a T.key * 'b
min_elt_exn map
Returns the (key, data)
pair corresponding to the
minimum key in map
, raises Not_found
if map
is empty.
val max_elt : ('a, 'b) T.t -> ('a T.key * 'b) option
max_elt map
Returns Some (key, data)
pair corresponding to the
maximum key in map
, and None if map
is empty.
val max_elt_exn : ('a, 'b) T.t -> 'a T.key * 'b
max_elt_exn map
Returns the (key, data)
pair corresponding to the
maximum key in map
, raises an exception if map
is empty.
val for_all : f:('a -> bool) -> ('b, 'a) T.t -> bool
same semantics as similar functions in List
val exists : f:('a -> bool) -> ('b, 'a) T.t -> bool