package olinq

  1. Overview
  2. Docs

Polymorphic Maps and Multimaps

type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
type 'a hash = 'a -> int
type 'a iter = ('a -> unit) -> unit

Basics

type ('a, +'b) t = private {
  1. is_empty : unit -> bool;
  2. size : unit -> int;
  3. get_exn : 'a -> 'b;
  4. iter : ('a -> 'b -> unit) -> unit;
  5. fold : 'c. ('c -> 'a -> 'b -> 'c) -> 'c -> 'c;
  6. choose : unit -> ('a * 'b) option;
}

Map from keys of type 'a to values of type 'b the type might change, it is exposed merely for variance checks w.r.t GADTs. Do not access fields directly.

type ('a, +'b) map = ('a, 'b) t
val get : ('a, 'b) t -> 'a -> 'b option
val get_exn : ('a, 'b) t -> 'a -> 'b
val mem : ('a, _) t -> 'a -> bool
val size : (_, _) t -> int
val to_iter : ('a, 'b) t -> ('a * 'b) iter
val to_iter_multimap : ('a, 'b list) t -> ('a * 'b) iter
val to_list : ('a, 'b) t -> ('a * 'b) list
val to_rev_list : ('a, 'b) t -> ('a * 'b) list
val fold : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> ('a, 'b) t -> 'acc

Fold on the items of the map

val fold_multimap : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> ('a, 'b list) t -> 'acc

Fold on the items of the multimap

val get_seq : 'a -> ('a, 'b) t -> 'b iter

Select a key from a map and wrap into iter

val iter : ('a, 'b) t -> ('a -> 'b -> unit) -> unit

View a multimap as a proper collection

val choose : ('a, 'b) t -> ('a * 'b) option

Build

Used to build new maps

module Build : sig ... end

Misc

val of_iter : ?src:'a Build.src -> ('a * 'b) iter -> ('a, 'b list) t
val of_list : ?src:'a Build.src -> ('a * 'b) list -> ('a, 'b list) t
val count_seq : ?src:'a Build.src -> 'a iter -> ('a, int) t
val map : ('b -> 'c) -> ('a, 'b) t -> ('a, 'c) t

Transform values

val reverse : ?src:'b Build.src -> ('a, 'b) t -> ('b, 'a list) t

Reverse relation of the map, as a multimap

val reverse_multimap : ?src:'b Build.src -> ('a, 'b list) t -> ('b, 'a list) t

Reverse relation of the multimap

val flatten : ('a, 'b iter) t -> ('a * 'b) iter

View a multimap as a collection of individual key/value pairs

val flatten_l : ('a, 'b list) t -> ('a * 'b) iter

View a multimap as a list of individual key/value pairs