CCMap.S
get k m
returns Some v
if the current binding of k
in m
is v
, or None
if the key k
is not present. Safe version of find
.
get_or k m ~default
returns the value associated to k
if present, and returns default
otherwise (if k
doesn't belong in m
).
update k f m
calls f (Some v)
if find k m = v
, otherwise it calls f None
. In any case, if the result is None
k
is removed from m
, and if the result is Some v'
then add k v' m
is returned.
choose_opt m
returns one binding of the given map m
, or None
if m
is empty. Safe version of choose
.
min_binding_opt m
returns the smallest binding of the given map m
, or None
if m
is empty. Safe version of min_binding
.
max_binding_opt m
returns the largest binding of the given map m
, or None
if m
is empty. Safe version of max_binding
.
find_opt k m
returns Some v
if the current binding of k
in m
is v
, or None
if the key k
is not present. Safe version of find
.
find_first f m
where f
is a monotonically increasing function, returns the binding of m
with the lowest key k
such that f k
, or raises Not_found
if no such key exists. See Map
.S.find_first.
find_first_opt f m
where f
is a monotonically increasing function, returns an option containing the binding of m
with the lowest key k
such that f k
, or None
if no such key exists. Safe version of find_first
.
val merge_safe :
f:( key -> [ `Left of 'a | `Right of 'b | `Both of 'a * 'b ] -> 'c option ) ->
'a t ->
'b t ->
'c t
merge_safe ~f a b
merges the maps a
and b
together.
add_seq m seq
adds the given Seq.t
of bindings to the map m
. Like add_list
. Renamed from add_std_seq
since 3.0.
add_seq ~f m l
adds the given seq l
of bindings to the map m
, using f
to combine values that have the same key. If a key occurs several times, all its bindings are combined using the function f
, with f key v1 v2
being called with v1
occurring later in the seq than v2
.
of_seq seq
builds a map from the given Seq.t
of bindings. Like of_list
. Renamed from of_std_seq
since 3.0.
of_seq_with ~f l
builds a map from the given seq l
of bindings k_i -> v_i
, added in order using add
. If a key occurs several times, all its bindings are combined using the function f
, with f key v1 v2
being called with v1
occurring later in the seq than v2
.
add_iter m iter
adds the given iter
of bindings to the map m
. Like add_list
.
add_iter ~f m l
adds the given iter l
of bindings to the map m
, using f
to combine values that have the same key. If a key occurs several times, all its bindings are combined using the function f
, with f key v1 v2
being called with v1
occurring later in the seq than v2
.
of_iter iter
builds a map from the given iter
of bindings. Like of_list
.
of_iter_with ~f l
builds a map from the given iter l
of bindings k_i -> v_i
, added in order using add
. If a key occurs several times, all its bindings are combined using the function f
, with f key v1 v2
being called with v1
occurring later in the iter than v2
.
to_iter m
iterates on the whole map m
, creating an iter
of bindings. Like to_list
.
of_list l
builds a map from the given list l
of bindings k_i -> v_i
, added in order using add
. If a key occurs several times, only its last binding will be present in the result.
of_list_with ~f l
builds a map from the given list l
of bindings k_i -> v_i
, added in order using add
. If a key occurs several times, all its bindings are combined using the function f
, with f key v1 v2
being called with v1
occurring later in the list than v2
.
add_list m l
adds the given list l
of bindings to the map m
.
add_list ~f m l
adds the given list l
of bindings to the map m
, using f
to combine values that have the same key. If a key occurs several times, all its bindings are combined using the function f
, with f key v1 v2
being called with v1
occurring later in the seq than v2
.
to_list m
builds a list of the bindings of the given map m
. The order is unspecified.