package containers-data

  1. Overview
  2. Docs
A set of advanced datatypes for containers

Install

Dune Dependency

Authors

Maintainers

Sources

v3.12.tar.gz
md5=d74226924b65697a8558eb34a6074417
sha512=d5094e362f9ad7fe91aa060ef5c9805812cf888b326f0f0070f929205a83169a64c78dfce58a2ec0da77555b21c69a1f287fb38da9867cd6b16507f6c20fa666

doc/containers-data/CCMixmap/index.html

Module CCMixmapSource

Maps with Heterogeneous Values

status: experimental

  module M = CCMixmap.Make(CCInt)

  let inj_int = CCMixmap.create_inj()
  let inj_str = CCMixmap.create_inj()
  let inj_list_int = CCMixmap.create_inj()

  let m =
    M.empty
    |> M.add ~inj:inj_int 1 1
    |> M.add ~inj:inj_str 2 "2"
    |> M.add ~inj:inj_list_int 3 [3;3;3]

      assert (M.get ~inj:inj_int 1 m = Some 1)
      assert (M.get ~inj:inj_str 1 m = None)
      assert (M.get ~inj:inj_str 2 m = Some "2")
      assert (M.get ~inj:inj_int 2 m = None)
      assert (M.get ~inj:inj_list_int 3 m = Some [3;3;3])
      assert (M.get ~inj:inj_str 3 m = None)

change of API, the map is last argument to make piping with |> easier since 0.16.

  • since 0.9
Sourcetype 'a injection

An accessor for values of type 'a in any map. Values put in the map using a key can only be retrieved using this very same key.

Sourceval create_inj : unit -> 'a injection

Return a value that works for a given type of values. This function is normally called once for each type of value. Several keys may be created for the same type, but a value set with a given setter can only be retrieved with the matching getter. The same key can be reused across multiple maps (although not in a thread-safe way).

Sourcemodule type S = sig ... end
Sourcemodule type ORD = sig ... end
Sourcemodule Make (X : ORD) : S with type key = X.t
OCaml

Innovation. Community. Security.