A map that folds in new values.

An example would be a multi-map in which a key is initialized with the empty list as its value, and adding a new key/value pair appends the value to the key's list.

module type Foldable = sig .. end
Input signature of the functor Make
type t
The type of the accumlator
type data
The type of the folded in values.
val init : t
The initial value of the accumulator.
val f : t -> data -> t
The folding function.
module type S = sig .. end
Output signature of the functor Make
type in_value
The type of the values being fold over.
type out_value
The type of the accumulator
type 'key t = private ('key, out_value) Core.Std.Map.Poly.t
type 'a _in_value = in_value
type 'a _out_value = out_value
type ('a, 'b) _t = 'a t
val empty : 'a t
A map containing no bindings
val singleton : 'a -> in_value -> 'a t
val is_empty : 'a t -> bool
val length : 'a t -> int
val add : key:'a -> data:in_value -> 'a t -> 'a t
add m ~key ~data adds the key to the value already bound to key in m. If no value is bound to key than the initial value specified by the functor will be used instead.
val find : 'a t -> 'a -> out_value
val remove : 'a t -> 'a -> 'a t
val set : key:'a -> data:out_value -> 'a t -> 'a t
val mem : 'a t -> 'a -> bool
val iter : 'a t -> f:(key:'a -> data:out_value -> unit) -> unit
val fold : 'a t -> init:'b -> f:(key:'a -> data:out_value -> 'b -> 'b) -> 'b
val filter : 'a t -> f:(key:'a -> data:out_value -> bool) -> 'a t
val keys : 'a t -> 'a list
val data : 'a t -> out_value list
val to_alist : 'a t -> ('a * out_value) list
val of_list : ('a * in_value) list -> 'a t
val for_all : 'a t -> f:(out_value -> bool) -> bool
val exists : 'a t -> f:(out_value -> bool) -> bool
val to_map : 'a t -> ('a, out_value) Core.Std.Map.Poly.t
val of_map : ('a, out_value) Core.Std.Map.Poly.t -> 'a t
module Make : 
functor (Fold : Foldable) -> S with type out_value = Fold.t and type in_value = Fold.data
Builds a fold_map
Sexpable interface
Same as above but builds the sexp_of and of_sexp functions. Requires the passed in types to be sexpable.
module type S_sexpable = sig .. end
include S
include Core.Std.Sexpable.S1 with type t := 'key t
module type Foldable_sexpable = sig .. end
include Foldable
include Core.Std.Sexpable with type t := t
module Make_sexpable : 
functor (Fold : Foldable_sexpable) -> S_sexpable with type out_value = Fold.t and type in_value = Fold.data

Polymorphic folds

Polymorphic fold take a

module type Foldable2 = sig .. end
type 'a t
val init : 'a t
val f : 'a t -> 'a -> 'a t
module type S2 = sig .. end
type 'a out_value
type ('key, 'data) t = private ('key, 'data out_value) Core.Std.Map.Poly.t
type 'a _in_value = 'a
type 'a _out_value = 'a out_value
type ('a, 'b) _t = ('a, 'b) t
val empty : ('a, 'b) t
val singleton : 'a -> 'b -> ('a, 'b) t
val is_empty : ('a, 'b) t -> bool
val length : ('a, 'b) t -> int
val add : key:'a -> data:'b -> ('a, 'b) t -> ('a, 'b) t
val find : ('a, 'b) t -> 'a -> 'b out_value
val remove : ('a, 'b) t -> 'a -> ('a, 'b) t
val set : key:'a -> data:'b out_value -> ('a, 'b) t -> ('a, 'b) t
val mem : ('a, 'b) t -> 'a -> bool
val iter : ('a, 'b) t -> f:(key:'a -> data:'b out_value -> unit) -> unit
val fold : ('a, 'b) t -> init:'c -> f:(key:'a -> data:'b out_value -> 'c -> 'c) -> 'c
val filter : ('a, 'b) t -> f:(key:'a -> data:'b out_value -> bool) -> ('a, 'b) t
val keys : ('a, 'b) t -> 'a list
val data : ('a, 'b) t -> 'b out_value list
val to_alist : ('a, 'b) t -> ('a * 'b out_value) list
val of_list : ('a * 'b) list -> ('a, 'b) t
val for_all : ('a, 'b) t -> f:('b out_value -> bool) -> bool
val exists : ('a, 'b) t -> f:('b out_value -> bool) -> bool
val to_map : ('a, 'b) t -> ('a, 'b out_value) Core.Std.Map.Poly.t
val of_map : ('a, 'b out_value) Core.Std.Map.Poly.t -> ('a, 'b) t
module Make2 : 
functor (Fold : Foldable2) -> S2 with type out_value = 'a Fold.t
Sexpable interface
module type Foldable2_sexpable = sig .. end
include Foldable2
include Core.Std.Sexpable.S1 with type t := 'a t
module type S2_sexpable = sig .. end
include S2
include Core.Std.Sexpable.S2 with type t := ('a, 'b) t
module Make2_sexpable : 
functor (Fold : Foldable2_sexpable) -> S2_sexpable with type out_value = 'a Fold.t

Predefined modules

module Cons : S2_sexpable with type out_value = 'a list
module Add : S_sexpable with type out_value = int and type in_value = int
A fold for adding. e.g. symbol positions
module Multiply : S_sexpable with type out_value = int and type in_value = int