<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Vec (vec.Vec)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../odoc.support/odoc.css"/><meta name="generator" content="odoc 2.4.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../odoc.support/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">vec</a> &#x00BB; Vec</nav><header class="odoc-preamble"><h1>Module <code><span>Vec</span></code></h1></header><nav class="odoc-toc"><ul><li><a href="#mutable-dynamic-arrays">Mutable dynamic arrays</a></li><li><a href="#reading-vector-properties">Reading vector properties</a></li><li><a href="#creating-vectors">Creating vectors</a></li><li><a href="#restricting-permissions">Restricting permissions</a></li><li><a href="#accessing-elements">Accessing elements</a></li><li><a href="#conversions">Conversions</a></li><li><a href="#modifying-vectors">Modifying vectors</a></li><li><a href="#transformations">Transformations</a></li><li><a href="#filters-&amp;-folds">Filters &amp; folds</a></li><li><a href="#combining-vectors">Combining vectors</a></li><li><a href="#querying-vectors">Querying vectors</a></li><li><a href="#sorting">Sorting</a></li><li><a href="#equality-and-comparison">Equality and comparison</a></li><li><a href="#iteration">Iteration</a></li><li><a href="#infix-operators">Infix operators</a></li></ul></nav><div class="odoc-content"><h2 id="mutable-dynamic-arrays"><a href="#mutable-dynamic-arrays" class="anchor"></a>Mutable dynamic arrays</h2><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, -'p) t</span></span></code></div></div><p>A value of type <code>('a, 'p) Vec.t</code> is a vector of values of type <code>'a</code>, with mutability permissions <code>'p</code>.</p><p>The permissions can be <code>[`R | `W]</code> for read-write vectors, <code>[`R]</code> for read-only vectors, or <code>[`W]</code> for write-only vectors.</p><h2 id="reading-vector-properties"><a href="#reading-vector-properties" class="anchor"></a>Reading vector properties</h2><div class="odoc-spec"><div class="spec value anchored" id="val-length"><a href="#val-length" class="anchor"></a><code><span><span class="keyword">val</span> length : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt;  ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Returns the length of the vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-capacity"><a href="#val-capacity" class="anchor"></a><code><span><span class="keyword">val</span> capacity : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt;  ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Returns the capacity of the vector.</p></div></div><h2 id="creating-vectors"><a href="#creating-vectors" class="anchor"></a>Creating vectors</h2><div class="odoc-spec"><div class="spec value anchored" id="val-make"><a href="#val-make" class="anchor"></a><code><span><span class="keyword">val</span> make : <span><span class="optlabel">?capacity</span>:int <span class="arrow">&#45;&gt;</span></span> <span>unit <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Constructs a vector with the specified capacity (defaults to 0).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-range"><a href="#val-range" class="anchor"></a><code><span><span class="keyword">val</span> range : <span>int <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span><span>(int, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Constructs a vector containing all numbers in the specified range. Both ascending and descending ranges are supported.</p></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><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Returns a singleton vector containing the specified item. (Applicative functor <code>pure</code> operation)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-copy"><a href="#val-copy" class="anchor"></a><code><span><span class="keyword">val</span> copy : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Creates a copy of the vector.</p></div></div><h2 id="restricting-permissions"><a href="#restricting-permissions" class="anchor"></a>Restricting permissions</h2><div class="odoc-spec"><div class="spec value anchored" id="val-as_read_only"><a href="#val-as_read_only" class="anchor"></a><code><span><span class="keyword">val</span> as_read_only : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Reinterprets the vector as a read-only vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-as_write_only"><a href="#val-as_write_only" class="anchor"></a><code><span><span class="keyword">val</span> as_write_only : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `W ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Reinterprets the vector as a write-only vector.</p></div></div><h2 id="accessing-elements"><a href="#accessing-elements" class="anchor"></a>Accessing elements</h2><div class="odoc-spec"><div class="spec value anchored" id="val-get"><a href="#val-get" class="anchor"></a><code><span><span class="keyword">val</span> get : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Gets the value in the vector at the specified index.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Invalid_argument]</code> <p>if the index is out of bounds.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_get"><a href="#val-try_get" class="anchor"></a><code><span><span class="keyword">val</span> try_get : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span></span></code></div><div class="spec-doc"><p>Gets the value in the vector at the specified index. Returns <code>None</code> if the index is out of range.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set"><a href="#val-set" class="anchor"></a><code><span><span class="keyword">val</span> set : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Sets the value in the vector at the specified index to the specified value.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Invalid_argument]</code> <p>if the index is out of bounds.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_set"><a href="#val-try_set" class="anchor"></a><code><span><span class="keyword">val</span> try_set : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Sets the value in the vector at the specified index to the specified value. Returns <code>false</code> if the index is out of range.</p></div></div><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><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>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</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>Returns the first element of the vector that satisfies the predicate.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Not_found]</code> <p>if no element satisfies the predicate.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_find"><a href="#val-try_find" class="anchor"></a><code><span><span class="keyword">val</span> try_find : <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>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</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>Returns the first element of the vector that satisfies the predicate, or <code>None</code>.</p></div></div><h2 id="conversions"><a href="#conversions" class="anchor"></a>Conversions</h2><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 class="type-var">'a</span> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Constructs a vector from the specified list.</p></div></div><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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> list</span></span></code></div><div class="spec-doc"><p>Constructs a list from the specified vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_array"><a href="#val-of_array" class="anchor"></a><code><span><span class="keyword">val</span> of_array : <span><span><span class="type-var">'a</span> array</span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Constructs a vector from a copy of the specified array.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_array"><a href="#val-to_array" class="anchor"></a><code><span><span class="keyword">val</span> to_array : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> array</span></span></code></div><div class="spec-doc"><p>Constructs an array containing the values of specified vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_array_unsafe"><a href="#val-of_array_unsafe" class="anchor"></a><code><span><span class="keyword">val</span> of_array_unsafe : <span><span><span class="type-var">'a</span> array</span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Constructs a vector from the specified array, without copying.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_array_unsafe"><a href="#val-to_array_unsafe" class="anchor"></a><code><span><span class="keyword">val</span> to_array_unsafe : <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> array</span></span></code></div><div class="spec-doc"><p>Returns the vector's underlying buffer. Note: The array may contain uninitialized elements.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pretty_print"><a href="#val-pretty_print" class="anchor"></a><code><span><span class="keyword">val</span> pretty_print : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> string)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Returns a string representation of the vector, using the specified function to format each value.</p></div></div><h2 id="modifying-vectors"><a href="#modifying-vectors" class="anchor"></a>Modifying vectors</h2><div class="odoc-spec"><div class="spec value anchored" id="val-clear"><a href="#val-clear" class="anchor"></a><code><span><span class="keyword">val</span> clear : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Resets the vector to an empty state.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-reserve"><a href="#val-reserve" class="anchor"></a><code><span><span class="keyword">val</span> reserve : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Ensures the vector's capacity is at least as large as the specified value, allocating if necessary.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-shrink_to_fit"><a href="#val-shrink_to_fit" class="anchor"></a><code><span><span class="keyword">val</span> shrink_to_fit : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Shrinks the vector's internal buffer to only be as large as the vector's length.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-push"><a href="#val-push" class="anchor"></a><code><span><span class="keyword">val</span> push : <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Pushes the specified item onto the end of the vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pop"><a href="#val-pop" class="anchor"></a><code><span><span class="keyword">val</span> pop : <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</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>Pops off the item from the end of the vector.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Invalid_argument]</code> <p>if the vector is empty.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_pop"><a href="#val-try_pop" class="anchor"></a><code><span><span class="keyword">val</span> try_pop : <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</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>Pops off the item from the end of the vector. Returns <code>None</code> if the vector is empty.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-insert_at"><a href="#val-insert_at" class="anchor"></a><code><span><span class="keyword">val</span> insert_at : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Inserts an item into the vector at the specified index.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Invalid_argument]</code> <p>if the index is out of bounds.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_insert_at"><a href="#val-try_insert_at" class="anchor"></a><code><span><span class="keyword">val</span> try_insert_at : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `W ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Inserts an item into the vector at the specified index. Returns <code>false</code> if the index is out of range.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-remove_at"><a href="#val-remove_at" class="anchor"></a><code><span><span class="keyword">val</span> remove_at : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</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>Removes and returns the item at the specified index.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Invalid_argument]</code> <p>if the index is out of bounds.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_remove_at"><a href="#val-try_remove_at" class="anchor"></a><code><span><span class="keyword">val</span> try_remove_at : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</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>Removes and returns the item at the specified index. Returns <code>None</code> if the index is out of range.</p></div></div><h2 id="transformations"><a href="#transformations" class="anchor"></a>Transformations</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>(<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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'b</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Maps the specified function over the vector, returning a new vector. (Functor <code>map</code> operation)</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>(<span>int <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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'b</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Like <a href="#val-map"><code>map</code></a>, but the function also takes the item's index as a parameter.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-map_in_place"><a href="#val-map_in_place" class="anchor"></a><code><span><span class="keyword">val</span> map_in_place : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Like <a href="#val-map"><code>map</code></a>, but the transformation is done in-place.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-flat_map"><a href="#val-flat_map" class="anchor"></a><code><span><span class="keyword">val</span> flat_map : 
  <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'b</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span>
  <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span>(<span class="type-var">'b</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Like <a href="#val-map"><code>map</code></a>, but flattens the result. (Monad <code>bind</code> operation)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rev"><a href="#val-rev" class="anchor"></a><code><span><span class="keyword">val</span> rev : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Returns a new vector that contains all the items in the specified vector, but in reverse order.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rev_in_place"><a href="#val-rev_in_place" class="anchor"></a><code><span><span class="keyword">val</span> rev_in_place : <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Reverses the vector in-place.</p></div></div><h2 id="filters-&amp;-folds"><a href="#filters-&amp;-folds" class="anchor"></a>Filters &amp; folds</h2><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>(<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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Returns a new vector containing only the items from the first vector that satisfy the specified predicate.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-filteri"><a href="#val-filteri" class="anchor"></a><code><span><span class="keyword">val</span> filteri : <span><span>(<span>int <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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Like <a href="#val-filter"><code>filter</code></a>, but the predicate also takes the item's index as a parameter.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-filter_in_place"><a href="#val-filter_in_place" class="anchor"></a><code><span><span class="keyword">val</span> filter_in_place : <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>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Performs a filter in-place, based on the specified predicate.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fold_left"><a href="#val-fold_left" class="anchor"></a><code><span><span class="keyword">val</span> fold_left : <span><span>(<span><span class="type-var">'b</span> <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 class="type-var">'b</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p>Folds the specified function and default value over the array, from left to right.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fold_right"><a href="#val-fold_right" class="anchor"></a><code><span><span class="keyword">val</span> fold_right : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p>Folds the specified function and default value over the array, from right to left.</p></div></div><h2 id="combining-vectors"><a href="#combining-vectors" class="anchor"></a>Combining vectors</h2><div class="odoc-spec"><div class="spec value anchored" id="val-append"><a href="#val-append" class="anchor"></a><code><span><span class="keyword">val</span> append : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Concatenates the two vectors into a new vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-append_in_place"><a href="#val-append_in_place" class="anchor"></a><code><span><span class="keyword">val</span> append_in_place : <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Appends the second vector to the first vector in-place.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-cartesian_product"><a href="#val-cartesian_product" class="anchor"></a><code><span><span class="keyword">val</span> cartesian_product : 
  <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span><span>(<span class="type-var">'b</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Cartesian product of 2 vectors. (Equivalent to <code>liftA2 (,)</code>)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-map2"><a href="#val-map2" class="anchor"></a><code><span><span class="keyword">val</span> map2 : 
  <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'c</span>)</span> <span class="arrow">&#45;&gt;</span></span>
  <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span><span>(<span class="type-var">'b</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span>(<span class="type-var">'c</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Maps the specified function over all combinations of tuples from the 2 vectors, returning a new vector. (Applicative functor <code>liftA2</code> operation</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-apply"><a href="#val-apply" class="anchor"></a><code><span><span class="keyword">val</span> apply : <span><span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'b</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Applies every function from the first vector to every value from the second vector, returning a new vector. (Applicatve functor <code>ap</code> operation)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-flatten"><a href="#val-flatten" class="anchor"></a><code><span><span class="keyword">val</span> flatten : <span><span><span>(<span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Flattens nested vectors into a single, one-dimensional vector. (Monad <code>join</code> operation)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-zip"><a href="#val-zip" class="anchor"></a><code><span><span class="keyword">val</span> zip : <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'b</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Zips the two vectors together.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-zip_with"><a href="#val-zip_with" class="anchor"></a><code><span><span class="keyword">val</span> zip_with : 
  <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'c</span>)</span> <span class="arrow">&#45;&gt;</span></span>
  <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span><span>(<span class="type-var">'b</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span>
  <span><span>(<span class="type-var">'c</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Zips the two vectors together, using the specified function to combine values.</p></div></div><h2 id="querying-vectors"><a href="#querying-vectors" class="anchor"></a>Querying vectors</h2><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>(<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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Returns <code>true</code> if any item in the vector satisfies the specified predicate.</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>(<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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Returns <code>true</code> if all items in the vector satisfy the specified predicate.</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><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Returns <code>true</code> if the specified item exists in the vector. Uses structural equality.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-memq"><a href="#val-memq" class="anchor"></a><code><span><span class="keyword">val</span> memq : <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Returns <code>true</code> if the specified item exists in the vector. Uses physical equality.</p></div></div><h2 id="sorting"><a href="#sorting" class="anchor"></a>Sorting</h2><div class="odoc-spec"><div class="spec value anchored" id="val-sort"><a href="#val-sort" class="anchor"></a><code><span><span class="keyword">val</span> sort : <span><span><span>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Sorts the vector in-place.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-sort_by"><a href="#val-sort_by" class="anchor"></a><code><span><span class="keyword">val</span> sort_by : <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>(<span class="type-var">'a</span>, <span>[ `R <span>| `W</span> ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Sorts the vector in-place, using the specified comparison function.</p></div></div><h2 id="equality-and-comparison"><a href="#equality-and-comparison" class="anchor"></a>Equality and comparison</h2><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><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Compares two vectors for equality.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-equal_by"><a href="#val-equal_by" class="anchor"></a><code><span><span class="keyword">val</span> equal_by : <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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Compares two vectors for equality, using the specified equality function for elements.</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><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Compares two vectors lexicographically.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-compare_by"><a href="#val-compare_by" class="anchor"></a><code><span><span class="keyword">val</span> compare_by : <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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Compares two vectors lexicographically, using the specified comparison function for elements.</p></div></div><h2 id="iteration"><a href="#iteration" class="anchor"></a>Iteration</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>(<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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Applies the specified function to each item in the vector.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-iteri"><a href="#val-iteri" class="anchor"></a><code><span><span class="keyword">val</span> iteri : <span><span>(<span>int <span class="arrow">&#45;&gt;</span></span> <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>(<span class="type-var">'a</span>, <span>[&gt; `R ]</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Like <a href="#val-iter"><code>iter</code></a>, but the function also takes the item's index as a parameter.</p></div></div><h2 id="infix-operators"><a href="#infix-operators" class="anchor"></a>Infix operators</h2><div class="odoc-spec"><div class="spec module anchored" id="module-Infix"><a href="#module-Infix" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Infix/index.html">Infix</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Contains infix versions of some vector operations, as well as <a href="https://v2.ocaml.org/manual/bindingops.html">binding operators</a> and <a href="https://v2.ocaml.org/manual/indexops.html">extended indexing operators</a>.</p></div></div></div></body></html>
