Total_mapA map that includes an entry for every possible value of the key type.
This is intended to be used on 'key types where there is a full enumeration of the type. In the common use case, 'key will be a simple variant type with [@@deriving compare, enumerate]. For example:
module Arrow_key = struct
module T = struct
type t =
| Up
| Down
| Left
| Right
[@@deriving sexp, bin_io, compare, enumerate]
end
include T
module Total_map = Total_map.Make (T)
endIn such a case, a t is semantically equivalent to a pure function from 'key to 'value. The differences are that it is serializable and that mapping or changing a t will produce a t using the same amount of space as the original.
However, in theory you could also modify the comparison function and enumeration, so long as the enumeration contains at least one representative of each equivalence class determined by the comparison function.
module Enumeration : sig ... endtype ('key, 'a, 'cmp, 'enum) t = private ('key, 'a, 'cmp) Core.Map.tval to_map : ('key, 'a, 'cmp, _) t -> ('key, 'a, 'cmp) Core.Map.t @@ portableMany of the functions below have types reflecting the fact that the maps are total (e.g., find does not return an option). The fact that they won't raise exceptions relies on the enumeration passed to Make being complete.
val iter_keys : ('key, _, _, _) t -> f:('key -> unit) -> unit @@ portableval iter : (_, 'a, _, _) t -> f:('a -> unit) -> unit @@ portableval iteri :
('key, 'a, _, _) t ->
f:(key:'key -> data:'a -> unit) ->
unit @@ portableval fold :
('key, 'a, _, _) t ->
init:'acc ->
f:(key:'key -> data:'a -> 'acc -> 'acc) ->
'acc @@ portableval fold_right :
('key, 'a, _, _) t ->
init:'acc ->
f:(key:'key -> data:'a -> 'acc -> 'acc) ->
'acc @@ portableval fold2 :
('key, 'a, 'cmp, 'enum) t ->
('key, 'b, 'cmp, 'enum) t ->
init:'acc ->
f:(key:'key -> 'a -> 'b -> 'acc -> 'acc) ->
'acc @@ portableFolds over two maps side by side, like iter2.
val to_alist :
?key_order:[ `Increasing | `Decreasing ] ->
('key, 'a, _, _) t ->
('key * 'a) list @@ portableval find : ('key, 'a, _, _) t -> 'key -> 'a @@ portableval combine_errors :
('key, 'a Core.Or_error.t, 'c, 'e) t ->
('key, 'a, 'c, 'e) t Core.Or_error.t @@ portableval data : (_, 'a, _, _) t -> 'a list @@ portableval for_all : (_, 'a, _, _) t -> f:('a -> bool) -> bool @@ portableval for_alli :
('key, 'a, _, _) t ->
f:(key:'key -> data:'a -> bool) ->
bool @@ portableval validate :
name:('key -> string) ->
'v Core.Validate.check ->
('key, 'v, _, _) t Core.Validate.check @@ portableval validatei :
name:('key -> string) ->
('key * 'v) Core.Validate.check ->
('key, 'v, _, _) t Core.Validate.check @@ portablemodule Sequence (A : Core.Applicative) : sig ... endSequence a total map of computations in order of their keys resulting in computation of the total map of results.
module Sequence2 (A : Core.Applicative.S2) : sig ... endmodule Sequence3 (A : Core.Applicative.S3) : sig ... endThe only reason that the Applicative interface isn't included here is that we don't have an Applicative.S4.
module type Key = sig ... endmodule type Key_plain = sig ... endmodule type Key_with_witnesses = sig ... endmodule type Key_plain_with_witnesses = sig ... endmodule type S_plain = sig ... endmodule type For_include_functor_plain = sig ... endmodule type S = sig ... endmodule type For_include_functor = sig ... endmodule Make_plain (Key : sig ... end) : sig ... endmodule Make_for_include_functor_plain (Key : sig ... end) : sig ... endmodule Make_plain_with_witnesses (Key : sig ... end) : sig ... endmodule Make_for_include_functor_plain_with_witnesses
(Key : sig ... end) :
sig ... endmodule Make_for_include_functor (Key : sig ... end) : sig ... endmodule Make_with_witnesses (Key : sig ... end) : sig ... endmodule Make_for_include_functor_with_witnesses
(Key : sig ... end) :
sig ... endmodule type M = sig ... endThe below functions allow writing things like type t = int M(T).t [@@deriving sexp]. Note that for sexp, bin_io, and compare alone this would not be useful, as T.Total_map.t already has those conversions. However, it could be useful to additionally derive sexp_grammar. (Sexp grammar functionality is upcoming.)
module M (T : For_include_functor_plain) : sig ... endval m__t_of_sexp :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
(Core.Sexp.t -> 'v) ->
Core.Sexp.t ->
('k, 'v, 'cmp, 'enum) t @@ portableval sexp_of_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
('v -> Core.Sexp.t) ->
('k, 'v, 'cmp, 'enum) t ->
Core.Sexp.t @@ portableval m__t_sexp_grammar :
(module Core.Map.M_sexp_grammar with type t = 'k) ->
'v Sexplib0.Sexp_grammar.t ->
('k, 'v, 'cmp, 'enum) t Sexplib0.Sexp_grammar.t @@ portableval bin_shape_m__t :
(module For_include_functor) ->
Bin_shape.t ->
Bin_shape.t @@ portableval bin_size_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Bin_prot.Size.sizer ->
('k, 'v, 'cmp, 'enum) t Core.Bin_prot.Size.sizer @@ portableval bin_write_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Bin_prot.Write.writer ->
('k, 'v, 'cmp, 'enum) t Core.Bin_prot.Write.writer @@ portableval bin_read_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Bin_prot.Read.reader ->
('k, 'v, 'cmp, 'enum) t Core.Bin_prot.Read.reader @@ portableval __bin_read_m__t__ :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Bin_prot.Read.reader ->
('k, 'v, 'cmp, 'enum) t Core.Bin_prot.Read.vtag_reader @@ portableval compare_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
('v -> 'v -> int) ->
('k, 'v, 'cmp, 'enum) t ->
('k, 'v, 'cmp, 'enum) t ->
int @@ portableval quickcheck_generator_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Quickcheck.Generator.t ->
('k, 'v, 'cmp, 'enum) t Core.Quickcheck.Generator.t @@ portableval quickcheck_observer_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Quickcheck.Observer.t ->
('k, 'v, 'cmp, 'enum) t Core.Quickcheck.Observer.t @@ portableval quickcheck_shrinker_m__t :
(module M
with type t = 'k
and type Total_map.comparator_witness = 'cmp
and type Total_map.enumeration_witness = 'enum) ->
'v Core.Quickcheck.Shrinker.t ->
('k, 'v, 'cmp, 'enum) t Core.Quickcheck.Shrinker.t @@ portablemodule Stable : sig ... end