Module Total_map

A 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)
  end

In 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 ... end
type ('key, 'a, 'cmp, 'enum) t = private ('key, 'a, 'cmp) Core.Map.t
val to_map : ('key, 'a, 'cmp, _) t -> ('key, 'a, 'cmp) Core.Map.t @@ portable

Many 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 map : ('key, 'a, 'c, 'e) t -> f:('a -> 'b) -> ('key, 'b, 'c, 'e) t @@ portable
val mapi : ('key, 'a, 'c, 'e) t -> f:(key:'key -> data:'a -> 'b) -> ('key, 'b, 'c, 'e) t @@ portable
val map2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:('a -> 'b -> 'c) -> ('key, 'c, 'cmp, 'enum) t @@ portable
val mapi2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:('key -> 'a -> 'b -> 'c) -> ('key, 'c, 'cmp, 'enum) t @@ portable
val unzip : ('key, 'a * 'b, 'cmp, 'enum) t -> ('key, 'a, 'cmp, 'enum) t * ('key, 'b, 'cmp, 'enum) t @@ portable
val iter_keys : ('key, _, _, _) t -> f:('key -> unit) -> unit @@ portable
val iter : (_, 'a, _, _) t -> f:('a -> unit) -> unit @@ portable
val iteri : ('key, 'a, _, _) t -> f:(key:'key -> data:'a -> unit) -> unit @@ portable
val iter2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:(key:'key -> 'a -> 'b -> unit) -> unit @@ portable
val fold : ('key, 'a, _, _) t -> init:'acc -> f:(key:'key -> data:'a -> 'acc -> 'acc) -> 'acc @@ portable
val fold_right : ('key, 'a, _, _) t -> init:'acc -> f:(key:'key -> data:'a -> 'acc -> 'acc) -> 'acc @@ portable
val fold2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> init:'acc -> f:(key:'key -> 'a -> 'b -> 'acc -> 'acc) -> 'acc @@ portable

Folds over two maps side by side, like iter2.

val set : ('key, 'a, 'cmp, 'enum) t -> 'key -> 'a -> ('key, 'a, 'cmp, 'enum) t @@ portable
val to_alist : ?key_order:[ `Increasing | `Decreasing ] -> ('key, 'a, _, _) t -> ('key * 'a) list @@ portable
val find : ('key, 'a, _, _) t -> 'key -> 'a @@ portable
val change : ('key, 'a, 'c, 'e) t -> 'key -> f:('a -> 'a) -> ('key, 'a, 'c, 'e) t @@ portable
val combine_errors : ('key, 'a Core.Or_error.t, 'c, 'e) t -> ('key, 'a, 'c, 'e) t Core.Or_error.t @@ portable
val data : (_, 'a, _, _) t -> 'a list @@ portable
val for_all : (_, 'a, _, _) t -> f:('a -> bool) -> bool @@ portable
val for_alli : ('key, 'a, _, _) t -> f:(key:'key -> data:'a -> bool) -> bool @@ portable
val validate : name:('key -> string) -> 'v Core.Validate.check -> ('key, 'v, _, _) t Core.Validate.check @@ portable
val validatei : name:('key -> string) -> ('key * 'v) Core.Validate.check -> ('key, 'v, _, _) t Core.Validate.check @@ portable
module Sequence (A : Core.Applicative) : sig ... end

Sequence 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 ... end
module Sequence3 (A : Core.Applicative.S3) : sig ... end

The only reason that the Applicative interface isn't included here is that we don't have an Applicative.S4.

module type Key = sig ... end
module type Key_plain = sig ... end
module type Key_with_witnesses = sig ... end
module type Key_plain_with_witnesses = sig ... end
module type S_plain = sig ... end
module type For_include_functor_plain = sig ... end
module type S = sig ... end
module type For_include_functor = sig ... end
module Make_plain (Key : sig ... end) : sig ... end
module Make_for_include_functor_plain (Key : sig ... end) : sig ... end
module Make_plain_with_witnesses (Key : sig ... end) : sig ... end
module Make_for_include_functor_plain_with_witnesses (Key : sig ... end) : sig ... end
module Make (Key : sig ... end) : sig ... end
module Make_for_include_functor (Key : sig ... end) : sig ... end
module Make_with_witnesses (Key : sig ... end) : sig ... end
module Make_for_include_functor_with_witnesses (Key : sig ... end) : sig ... end
module type M = sig ... end

The 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 ... end
val 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 @@ portable
val 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 @@ portable
val 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 @@ portable
val bin_shape_m__t : (module For_include_functor) -> Bin_shape.t -> Bin_shape.t @@ portable
val 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 @@ portable
val 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 @@ portable
val 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 @@ portable
val __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 @@ portable
val 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 @@ portable
val 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 @@ portable
val 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 @@ portable
val 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 @@ portable
module Stable : sig ... end