ocaml-containers/dev/containers-data/CCMixmap/index.html
2023-02-15 17:36:59 +00:00

19 lines
No EOL
3.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>CCMixmap (containers-data.CCMixmap)</title><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../index.html">containers-data</a> &#x00BB; CCMixmap</nav><header class="odoc-preamble"><h1>Module <code><span>CCMixmap</span></code></h1><p>Maps with Heterogeneous Values</p><p><b>status: experimental</b></p><pre class="language-ocaml"><code>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
|&gt; M.add ~inj:inj_int 1 1
|&gt; M.add ~inj:inj_str 2 &quot;2&quot;
|&gt; 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 &quot;2&quot;)
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)</code></pre><p>change of API, the map is last argument to make piping with <code>|&gt;</code> easier since 0.16.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.9</li></ul></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-injection"><a href="#type-injection" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a injection</span></span></code></div><div class="spec-doc"><p>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.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create_inj"><a href="#val-create_inj" class="anchor"></a><code><span><span class="keyword">val</span> create_inj : <span>unit <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-injection">injection</a></span></span></code></div><div class="spec-doc"><p>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).</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-S"><a href="#module-type-S" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-S/index.html">S</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-ORD"><a href="#module-type-ORD" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-ORD/index.html">ORD</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Make"><a href="#module-Make" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Make/index.html">Make</a></span><span> (<a href="Make/argument-1-X/index.html">X</a> : <a href="module-type-ORD/index.html">ORD</a>) : <a href="module-type-S/index.html">S</a> <span class="keyword">with</span> <span><span class="keyword">type</span> <a href="module-type-S/index.html#type-key">key</a> = <a href="Make/argument-1-X/index.html#type-t">X.t</a></span></span></code></div></div></div></body></html>