linol/lsp/Lsp/Private/Substring/Map/index.html
2024-02-20 18:15:51 +00:00

8 lines
39 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>Map (lsp.Lsp.Private.Substring.Map)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.1"/><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">lsp</a> &#x00BB; <a href="../../../index.html">Lsp</a> &#x00BB; <a href="../../index.html">Private</a> &#x00BB; <a href="../index.html">Substring</a> &#x00BB; Map</nav><header class="odoc-preamble"><h1>Module <code><span>Substring.Map</span></code></h1></header><nav class="odoc-toc"><ul><li><a href="#maps">Maps</a></li><li><a href="#bindings">Bindings</a></li><li><a href="#searching">Searching</a></li><li><a href="#traversing">Traversing</a></li><li><a href="#transforming">Transforming</a></li><li><a href="#predicates">Predicates and comparisons</a></li><li><a href="#converting">Converting</a></li></ul></nav><div class="odoc-content"><h2 id="maps"><a href="#maps" class="anchor"></a>Maps</h2><div class="odoc-spec"><div class="spec type anchored" id="type-key"><a href="#type-key" class="anchor"></a><code><span><span class="keyword">type</span> key</span><span> = <a href="../index.html#type-t">t</a></span></code></div><div class="spec-doc"><p>The type of the map keys.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> <span>!+'a t</span></span></code></div><div class="spec-doc"><p>The type of maps from type <code>key</code> to type <code>'a</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span><span class="keyword">val</span> empty : <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>The empty map.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add"><a href="#val-add" class="anchor"></a><code><span><span class="keyword">val</span> add : <span><span class="label">key</span>:<a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">data</span>:<span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>add ~key ~data m</code> returns a map containing the same bindings as <code>m</code>, plus a binding of <code>key</code> to <code>data</code>. If <code>key</code> was already bound in <code>m</code> to a value that is physically equal to <code>data</code>, <code>m</code> is returned unchanged (the result of the function is then physically equal to <code>m</code>). Otherwise, the previous binding of <code>key</code> in <code>m</code> disappears.</p><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">4.03</span> <p>Physical equality was not ensured.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_to_list"><a href="#val-add_to_list" class="anchor"></a><code><span><span class="keyword">val</span> add_to_list : <span><span class="label">key</span>:<a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">data</span>:<span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span><span class="type-var">'a</span> list</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> list</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>add_to_list ~key ~data m</code> is <code>m</code> with <code>key</code> mapped to <code>l</code> such that <code>l</code> is <code>data :: Map.find key m</code> if <code>key</code> was bound in <code>m</code> and <code>[v]</code> otherwise.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 5.1</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-update"><a href="#val-update" class="anchor"></a><code><span><span class="keyword">val</span> update : <span><span class="label">key</span>:<a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">f</span>:<span>(<span><span><span class="type-var">'a</span> option</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>update ~key ~f m</code> returns a map containing the same bindings as <code>m</code>, except for the binding of <code>key</code>. Depending on the value of <code>y</code> where <code>y</code> is <code>f (find_opt key m)</code>, the binding of <code>key</code> is added, removed or updated. If <code>y</code> is <code>None</code>, the binding is removed if it exists; otherwise, if <code>y</code> is <code>Some z</code> then <code>key</code> is associated to <code>z</code> in the resulting map. If <code>key</code> was already bound in <code>m</code> to a value that is physically equal to <code>z</code>, <code>m</code> is returned unchanged (the result of the function is then physically equal to <code>m</code>).</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.06</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-singleton"><a href="#val-singleton" class="anchor"></a><code><span><span class="keyword">val</span> singleton : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>singleton x y</code> returns the one-element map that contains a binding <code>y</code> for <code>x</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-remove"><a href="#val-remove" class="anchor"></a><code><span><span class="keyword">val</span> remove : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>remove x m</code> returns a map containing the same bindings as <code>m</code>, except for <code>x</code> which is unbound in the returned map. If <code>x</code> was not in <code>m</code>, <code>m</code> is returned unchanged (the result of the function is then physically equal to <code>m</code>).</p><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">4.03</span> <p>Physical equality was not ensured.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-merge"><a href="#val-merge" class="anchor"></a><code><span><span class="keyword">val</span> merge :
<span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> option</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'b</span> option</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'c</span> option</span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span><span><span class="type-var">'b</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="type-var">'c</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>merge ~f m1 m2</code> computes a map whose keys are a subset of the keys of <code>m1</code> and of <code>m2</code>. The presence of each such binding, and the corresponding value, is determined with the function <code>f</code>. In terms of the <code>find_opt</code> operation, we have <code>find_opt x (merge f m1 m2) = f x (find_opt x m1) (find_opt x m2)</code> for any key <code>x</code>, provided that <code>f x None None = None</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-union"><a href="#val-union" class="anchor"></a><code><span><span class="keyword">val</span> union : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>union ~f m1 m2</code> computes a map whose keys are a subset of the keys of <code>m1</code> and of <code>m2</code>. When the same binding is defined in both arguments, the function <code>f</code> is used to combine them. This is a special case of <code>merge</code>: <code>union f m1 m2</code> is equivalent to <code>merge f' m1 m2</code>, where</p><ul><li><code>f' _key None None = None</code></li><li><code>f' _key (Some v) None = Some v</code></li><li><code>f' _key None (Some v) = Some v</code></li><li><code>f' key (Some v1) (Some v2) = f key v1 v2</code></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.03</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-cardinal"><a href="#val-cardinal" class="anchor"></a><code><span><span class="keyword">val</span> cardinal : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Return the number of bindings of a map.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><h2 id="bindings"><a href="#bindings" class="anchor"></a>Bindings</h2><div class="odoc-spec"><div class="spec value anchored" id="val-bindings"><a href="#val-bindings" class="anchor"></a><code><span><span class="keyword">val</span> bindings : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> list</span></span></code></div><div class="spec-doc"><p>Return the list of all bindings of the given map. The returned list is sorted in increasing order of keys with respect to the ordering <code>Ord.compare</code>, where <code>Ord</code> is the argument given to <code>Map.Make</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-min_binding"><a href="#val-min_binding" class="anchor"></a><code><span><span class="keyword">val</span> min_binding : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-key">key</a> * <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Return the binding with the smallest key in a given map (with respect to the <code>Ord.compare</code> ordering), or raise <code>Not_found</code> if the map is empty.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-min_binding_opt"><a href="#val-min_binding_opt" class="anchor"></a><code><span><span class="keyword">val</span> min_binding_opt : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> option</span></span></code></div><div class="spec-doc"><p>Return the binding with the smallest key in the given map (with respect to the <code>Ord.compare</code> ordering), or <code>None</code> if the map is empty.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-max_binding"><a href="#val-max_binding" class="anchor"></a><code><span><span class="keyword">val</span> max_binding : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-key">key</a> * <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Same as <code>min_binding</code>, but returns the binding with the largest key in the given map.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-max_binding_opt"><a href="#val-max_binding_opt" class="anchor"></a><code><span><span class="keyword">val</span> max_binding_opt : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> option</span></span></code></div><div class="spec-doc"><p>Same as <code>min_binding_opt</code>, but returns the binding with the largest key in the given map.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-choose"><a href="#val-choose" class="anchor"></a><code><span><span class="keyword">val</span> choose : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-key">key</a> * <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Return one binding of the given map, or raise <code>Not_found</code> if the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-choose_opt"><a href="#val-choose_opt" class="anchor"></a><code><span><span class="keyword">val</span> choose_opt : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> option</span></span></code></div><div class="spec-doc"><p>Return one binding of the given map, or <code>None</code> if the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><h2 id="searching"><a href="#searching" class="anchor"></a>Searching</h2><div class="odoc-spec"><div class="spec value anchored" id="val-find"><a href="#val-find" class="anchor"></a><code><span><span class="keyword">val</span> find : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>find x m</code> returns the current value of <code>x</code> in <code>m</code>, or raises <code>Not_found</code> if no binding for <code>x</code> exists.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_opt"><a href="#val-find_opt" class="anchor"></a><code><span><span class="keyword">val</span> find_opt : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span></span></code></div><div class="spec-doc"><p><code>find_opt x m</code> returns <code>Some v</code> if the current value of <code>x</code> in <code>m</code> is <code>v</code>, or <code>None</code> if no binding for <code>x</code> exists.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_first"><a href="#val-find_first" class="anchor"></a><code><span><span class="keyword">val</span> find_first : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-key">key</a> * <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>find_first ~f m</code>, where <code>f</code> is a monotonically increasing function, returns the binding of <code>m</code> with the lowest key <code>k</code> such that <code>f k</code>, or raises <code>Not_found</code> if no such key exists.</p><p>For example, <code>find_first (fun k -&gt; Ord.compare k x &gt;= 0) m</code> will return the first binding <code>k, v</code> of <code>m</code> where <code>Ord.compare k x &gt;= 0</code> (intuitively: <code>k &gt;= x</code>), or raise <code>Not_found</code> if <code>x</code> is greater than any element of <code>m</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_first_opt"><a href="#val-find_first_opt" class="anchor"></a><code><span><span class="keyword">val</span> find_first_opt : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> option</span></span></code></div><div class="spec-doc"><p><code>find_first_opt ~f m</code>, where <code>f</code> is a monotonically increasing function, returns an option containing the binding of <code>m</code> with the lowest key <code>k</code> such that <code>f k</code>, or <code>None</code> if no such key exists.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_last"><a href="#val-find_last" class="anchor"></a><code><span><span class="keyword">val</span> find_last : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-key">key</a> * <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>find_last ~f m</code>, where <code>f</code> is a monotonically decreasing function, returns the binding of <code>m</code> with the highest key <code>k</code> such that <code>f k</code>, or raises <code>Not_found</code> if no such key exists.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_last_opt"><a href="#val-find_last_opt" class="anchor"></a><code><span><span class="keyword">val</span> find_last_opt : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> option</span></span></code></div><div class="spec-doc"><p><code>find_last_opt ~f m</code>, where <code>f</code> is a monotonically decreasing function, returns an option containing the binding of <code>m</code> with the highest key <code>k</code> such that <code>f k</code>, or <code>None</code> if no such key exists.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><h2 id="traversing"><a href="#traversing" class="anchor"></a>Traversing</h2><div class="odoc-spec"><div class="spec value anchored" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span><span class="keyword">val</span> iter : <span><span class="label">f</span>:<span>(<span><span class="label">key</span>:<a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">data</span>:<span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>iter ~f m</code> applies <code>f</code> to all bindings in map <code>m</code>. <code>f</code> receives the key as first argument, and the associated value as second argument. The bindings are passed to <code>f</code> in increasing order with respect to the ordering over the type of the keys.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fold"><a href="#val-fold" class="anchor"></a><code><span><span class="keyword">val</span> fold : <span><span class="label">f</span>:<span>(<span><span class="label">key</span>:<a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">data</span>:<span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'acc</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'acc</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">init</span>:<span class="type-var">'acc</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'acc</span></span></code></div><div class="spec-doc"><p><code>fold ~f m ~init</code> computes <code>(f kN dN ... (f k1 d1 init)...)</code>, where <code>k1 ... kN</code> are the keys of all bindings in <code>m</code> (in increasing order), and <code>d1 ... dN</code> are the associated data.</p></div></div><h2 id="transforming"><a href="#transforming" class="anchor"></a>Transforming</h2><div class="odoc-spec"><div class="spec value anchored" id="val-map"><a href="#val-map" class="anchor"></a><code><span><span class="keyword">val</span> map : <span><span class="label">f</span>:<span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>map ~f m</code> returns a map with same domain as <code>m</code>, where the associated value <code>a</code> of all bindings of <code>m</code> has been replaced by the result of the application of <code>f</code> to <code>a</code>. The bindings are passed to <code>f</code> in increasing order with respect to the ordering over the type of the keys.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mapi"><a href="#val-mapi" class="anchor"></a><code><span><span class="keyword">val</span> mapi : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Same as <code>map</code>, but the function receives as arguments both the key and the associated value for each binding of the map.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-filter"><a href="#val-filter" class="anchor"></a><code><span><span class="keyword">val</span> filter : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>filter ~f m</code> returns the map with all the bindings in <code>m</code> that satisfy predicate <code>p</code>. If every binding in <code>m</code> satisfies <code>f</code>, <code>m</code> is returned unchanged (the result of the function is then physically equal to <code>m</code>)</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">4.03</span> <p>Physical equality was not ensured.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-filter_map"><a href="#val-filter_map" class="anchor"></a><code><span><span class="keyword">val</span> filter_map : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> option</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>filter_map ~f m</code> applies the function <code>f</code> to every binding of <code>m</code>, and builds a map from the results. For each binding <code>(k, v)</code> in the input map:</p><ul><li>if <code>f k v</code> is <code>None</code> then <code>k</code> is not in the result,</li><li>if <code>f k v</code> is <code>Some v'</code> then the binding <code>(k, v')</code> is in the output map.</li></ul><p>For example, the following function on maps whose values are lists</p><pre class="language-ocaml"><code>filter_map
(fun _k li -&gt; match li with [] -&gt; None | _::tl -&gt; Some tl)
m</code></pre><p>drops all bindings of <code>m</code> whose value is an empty list, and pops the first element of each value that is non-empty.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.11</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-partition"><a href="#val-partition" class="anchor"></a><code><span><span class="keyword">val</span> partition : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span> * <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>partition ~f m</code> returns a pair of maps <code>(m1, m2)</code>, where <code>m1</code> contains all the bindings of <code>m</code> that satisfy the predicate <code>f</code>, and <code>m2</code> is the map with all the bindings of <code>m</code> that do not satisfy <code>f</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-split"><a href="#val-split" class="anchor"></a><code><span><span class="keyword">val</span> split : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span> * <span><span class="type-var">'a</span> option</span> * <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>split x m</code> returns a triple <code>(l, data, r)</code>, where <code>l</code> is the map with all the bindings of <code>m</code> whose key is strictly less than <code>x</code>; <code>r</code> is the map with all the bindings of <code>m</code> whose key is strictly greater than <code>x</code>; <code>data</code> is <code>None</code> if <code>m</code> contains no binding for <code>x</code>, or <code>Some v</code> if <code>m</code> binds <code>v</code> to <code>x</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><h2 id="predicates"><a href="#predicates" class="anchor"></a>Predicates and comparisons</h2><div class="odoc-spec"><div class="spec value anchored" id="val-is_empty"><a href="#val-is_empty" class="anchor"></a><code><span><span class="keyword">val</span> is_empty : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Test whether a map is empty or not.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mem"><a href="#val-mem" class="anchor"></a><code><span><span class="keyword">val</span> mem : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>mem x m</code> returns <code>true</code> if <code>m</code> contains a binding for <code>x</code>, and <code>false</code> otherwise.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-equal"><a href="#val-equal" class="anchor"></a><code><span><span class="keyword">val</span> equal : <span><span class="label">cmp</span>:<span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>equal ~cmp m1 m2</code> tests whether the maps <code>m1</code> and <code>m2</code> are equal, that is, contain equal keys and associate them with equal data. <code>cmp</code> is the equality predicate used to compare the data associated with the keys.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span><span class="keyword">val</span> compare : <span><span class="label">cmp</span>:<span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> int)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Total ordering between maps. The first argument is a total ordering used to compare data associated with equal keys in the two maps.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-for_all"><a href="#val-for_all" class="anchor"></a><code><span><span class="keyword">val</span> for_all : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>for_all ~f m</code> checks if all the bindings of the map satisfy the predicate <code>f</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-exists"><a href="#val-exists" class="anchor"></a><code><span><span class="keyword">val</span> exists : <span><span class="label">f</span>:<span>(<span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>exists ~f m</code> checks if at least one binding of the map satisfies the predicate <code>f</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.12</li></ul></div></div><h2 id="converting"><a href="#converting" class="anchor"></a>Converting</h2><div class="odoc-spec"><div class="spec value anchored" id="val-to_list"><a href="#val-to_list" class="anchor"></a><code><span><span class="keyword">val</span> to_list : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> list</span></span></code></div><div class="spec-doc"><p><code>to_list m</code> is <code>bindings</code><code> m</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 5.1</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_list"><a href="#val-of_list" class="anchor"></a><code><span><span class="keyword">val</span> of_list : <span><span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>of_list bs</code> adds the bindings of <code>bs</code> to the empty map, in list order (if a key is bound twice in <code>bs</code> the last one takes over).</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 5.1</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_seq"><a href="#val-to_seq" class="anchor"></a><code><span><span class="keyword">val</span> to_seq : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> <a href="../../../../../ocaml/Stdlib/Seq/index.html#type-t">Seq.t</a></span></span></code></div><div class="spec-doc"><p>Iterate on the whole map, in ascending order of keys</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_rev_seq"><a href="#val-to_rev_seq" class="anchor"></a><code><span><span class="keyword">val</span> to_rev_seq : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> <a href="../../../../../ocaml/Stdlib/Seq/index.html#type-t">Seq.t</a></span></span></code></div><div class="spec-doc"><p>Iterate on the whole map, in descending order of keys</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.12</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_seq_from"><a href="#val-to_seq_from" class="anchor"></a><code><span><span class="keyword">val</span> to_seq_from : <span><a href="#type-key">key</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> <a href="../../../../../ocaml/Stdlib/Seq/index.html#type-t">Seq.t</a></span></span></code></div><div class="spec-doc"><p><code>to_seq_from k m</code> iterates on a subset of the bindings of <code>m</code>, in ascending order of keys, from key <code>k</code> or above.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_seq"><a href="#val-add_seq" class="anchor"></a><code><span><span class="keyword">val</span> add_seq : <span><span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> <a href="../../../../../ocaml/Stdlib/Seq/index.html#type-t">Seq.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Add the given bindings to the map, in order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_seq"><a href="#val-of_seq" class="anchor"></a><code><span><span class="keyword">val</span> of_seq : <span><span><span>(<a href="#type-key">key</a> * <span class="type-var">'a</span>)</span> <a href="../../../../../ocaml/Stdlib/Seq/index.html#type-t">Seq.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Build a map from the given bindings</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div></div></body></html>