iter/1.1/sequence/SequenceLabels/index.html
2019-03-08 19:15:01 -06:00

2 lines
No EOL
82 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>SequenceLabels (sequence.SequenceLabels)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../index.html">sequence</a> &#x00BB; SequenceLabels</nav><h1>Module <code>SequenceLabels</code></h1><h2 id="simple-and-efficient-iterators"><a href="#simple-and-efficient-iterators" class="anchor"></a>Simple and Efficient Iterators</h2><p>Version of <a href="../Sequence/index.html"><code>Sequence</code></a> with labels</p><dl><dt>since</dt><dd>0.5.5</dd></dl><nav class="toc"><ul><li><a href="#build-a-sequence">Build a sequence</a></li><li><a href="#consume-a-sequence">Consume a sequence</a></li><li><a href="#transform-a-sequence">Transform a sequence</a></li><li><a href="#caching">Caching</a></li><li><a href="#misc">Misc</a></li><li><a href="#basic-data-structures-converters">Basic data structures converters</a></li><li><a href="#functorial-conversions-between-sets-and-sequences">Functorial conversions between sets and sequences</a></li><li><a href="#conversion-between-maps-and-sequences.">Conversion between maps and sequences.</a></li><li><a href="#infinite-sequences-of-random-values">Infinite sequences of random values</a></li><li><a href="#sampling">Sampling</a></li><li><a href="#infix-functions">Infix functions</a></li><li><a href="#pretty-printing-of-sequences">Pretty printing of sequences</a></li><li><a href="#basic-io">Basic IO</a></li></ul></nav></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> +'a t</code><code> = (<span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> unit</code></dt><dd><p>A sequence of values of type <code>'a</code>. If you give it a function <code>'a -&gt; unit</code> it will be applied to every element of the sequence successively.</p></dd></dl><dl><dt class="spec type" id="type-sequence"><a href="#type-sequence" class="anchor"></a><code><span class="keyword">type</span> +'a sequence</code><code> = <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt></dl><aside><p><b>NOTE</b> Type <code>('a, 'b) t2 = ('a -&gt; 'b -&gt; unit) -&gt; unit</code> has been removed and subsumed by <code>('a * 'b) t</code> </p><dl><dt>since</dt><dd>1.0</dd></dl></aside><dl><dt class="spec type" id="type-equal"><a href="#type-equal" class="anchor"></a><code><span class="keyword">type</span> 'a equal</code><code> = <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool</code></dt><dt class="spec type" id="type-hash"><a href="#type-hash" class="anchor"></a><code><span class="keyword">type</span> 'a hash</code><code> = <span class="type-var">'a</span> <span>&#45;&gt;</span> int</code></dt></dl><section><header><h3 id="build-a-sequence"><a href="#build-a-sequence" class="anchor"></a>Build a sequence</h3></header><dl><dt class="spec value" id="val-from_iter"><a href="#val-from_iter" class="anchor"></a><code><span class="keyword">val</span> from_iter : ((<span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Build a sequence from a iter function</p></dd></dl><dl><dt class="spec value" id="val-from_fun"><a href="#val-from_fun" class="anchor"></a><code><span class="keyword">val</span> from_fun : (unit <span>&#45;&gt;</span> <span class="type-var">'a</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Call the function repeatedly until it returns None. This sequence is transient, use <a href="index.html#val-persistent"><code>persistent</code></a> if needed!</p></dd></dl><dl><dt class="spec value" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span class="keyword">val</span> empty : <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Empty sequence. It contains no element.</p></dd></dl><dl><dt class="spec value" id="val-singleton"><a href="#val-singleton" class="anchor"></a><code><span class="keyword">val</span> singleton : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Singleton sequence, with exactly one element.</p></dd></dl><dl><dt class="spec value" id="val-doubleton"><a href="#val-doubleton" class="anchor"></a><code><span class="keyword">val</span> doubleton : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence with exactly two elements</p></dd></dl><dl><dt class="spec value" id="val-init"><a href="#val-init" class="anchor"></a><code><span class="keyword">val</span> init : f:(int <span>&#45;&gt;</span> <span class="type-var">'a</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>init f</code> is the infinite sequence <code>f 0; f 1; f 2; …</code>.</p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-cons"><a href="#val-cons" class="anchor"></a><code><span class="keyword">val</span> cons : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>cons x l</code> yields <code>x</code>, then yields from <code>l</code>. Same as <code>append (singleton x) l</code></p></dd></dl><dl><dt class="spec value" id="val-snoc"><a href="#val-snoc" class="anchor"></a><code><span class="keyword">val</span> snoc : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Same as <a href="index.html#val-cons"><code>cons</code></a> but yields the element after iterating on <code>l</code></p></dd></dl><dl><dt class="spec value" id="val-return"><a href="#val-return" class="anchor"></a><code><span class="keyword">val</span> return : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Synonym to <a href="index.html#val-singleton"><code>singleton</code></a></p></dd></dl><dl><dt class="spec value" id="val-pure"><a href="#val-pure" class="anchor"></a><code><span class="keyword">val</span> pure : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Synonym to <a href="index.html#val-singleton"><code>singleton</code></a></p></dd></dl><dl><dt class="spec value" id="val-repeat"><a href="#val-repeat" class="anchor"></a><code><span class="keyword">val</span> repeat : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Infinite sequence of the same element. You may want to look at <a href="index.html#val-take"><code>take</code></a> and the likes if you iterate on it.</p></dd></dl><dl><dt class="spec value" id="val-iterate"><a href="#val-iterate" class="anchor"></a><code><span class="keyword">val</span> iterate : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>iterate f x</code> is the infinite sequence <code>x, f(x), f(f(x)), ...</code></p></dd></dl><dl><dt class="spec value" id="val-forever"><a href="#val-forever" class="anchor"></a><code><span class="keyword">val</span> forever : (unit <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence that calls the given function to produce elements. The sequence may be transient (depending on the function), and definitely is infinite. You may want to use <a href="index.html#val-take"><code>take</code></a> and <a href="index.html#val-persistent"><code>persistent</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-cycle"><a href="#val-cycle" class="anchor"></a><code><span class="keyword">val</span> cycle : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Cycle forever through the given sequence. Assume the given sequence can be traversed any amount of times (not transient). This yields an infinite sequence, you should use something like <a href="index.html#val-take"><code>take</code></a> not to loop forever.</p></dd></dl></section><section><header><h3 id="consume-a-sequence"><a href="#consume-a-sequence" class="anchor"></a>Consume a sequence</h3></header><dl><dt class="spec value" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span class="keyword">val</span> iter : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Consume the sequence, passing all its arguments to the function. Basically <code>iter f seq</code> is just <code>seq f</code>.</p></dd></dl><dl><dt class="spec value" id="val-iteri"><a href="#val-iteri" class="anchor"></a><code><span class="keyword">val</span> iteri : f:(int <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Iterate on elements and their index in the sequence</p></dd></dl><dl><dt class="spec value" id="val-fold"><a href="#val-fold" class="anchor"></a><code><span class="keyword">val</span> fold : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span>) <span>&#45;&gt;</span> init:<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Fold over elements of the sequence, consuming it</p></dd></dl><dl><dt class="spec value" id="val-foldi"><a href="#val-foldi" class="anchor"></a><code><span class="keyword">val</span> foldi : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> int <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span>) <span>&#45;&gt;</span> init:<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Fold over elements of the sequence and their index, consuming it</p></dd></dl><dl><dt class="spec value" id="val-fold_map"><a href="#val-fold_map" class="anchor"></a><code><span class="keyword">val</span> fold_map : f:(<span class="type-var">'acc</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'acc</span> * <span class="type-var">'b</span>) <span>&#45;&gt;</span> init:<span class="type-var">'acc</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>fold_map f acc l</code> is like <a href="index.html#val-map"><code>map</code></a>, but it carries some state as in <a href="index.html#val-fold"><code>fold</code></a>. The state is not returned, it is just used to thread some information to the map function.</p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-fold_filter_map"><a href="#val-fold_filter_map" class="anchor"></a><code><span class="keyword">val</span> fold_filter_map : f:(<span class="type-var">'acc</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'acc</span> * <span class="type-var">'b</span> option) <span>&#45;&gt;</span> init:<span class="type-var">'acc</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>fold_filter_map f acc l</code> is a <a href="index.html#val-fold_map"><code>fold_map</code></a>-like function, but the function can choose to skip an element by retuning <code>None</code>.</p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-map"><a href="#val-map" class="anchor"></a><code><span class="keyword">val</span> map : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map objects of the sequence into other elements, lazily</p></dd></dl><dl><dt class="spec value" id="val-mapi"><a href="#val-mapi" class="anchor"></a><code><span class="keyword">val</span> mapi : f:(int <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map objects, along with their index in the sequence</p></dd></dl><dl><dt class="spec value" id="val-map_by_2"><a href="#val-map_by_2" class="anchor"></a><code><span class="keyword">val</span> map_by_2 : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map objects two by two. lazily. The last element is kept in the sequence if the count is odd.</p><dl><dt>since</dt><dd>0.7</dd></dl></dd></dl><dl><dt class="spec value" id="val-for_all"><a href="#val-for_all" class="anchor"></a><code><span class="keyword">val</span> for_all : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> bool</code></dt><dd><p>Do all elements satisfy the predicate?</p></dd></dl><dl><dt class="spec value" id="val-exists"><a href="#val-exists" class="anchor"></a><code><span class="keyword">val</span> exists : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> bool</code></dt><dd><p>Exists there some element satisfying the predicate?</p></dd></dl><dl><dt class="spec value" id="val-mem"><a href="#val-mem" class="anchor"></a><code><span class="keyword">val</span> mem : ?&#8288;eq:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> x:<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the value a member of the sequence?</p><dl><dt>parameter eq</dt><dd><p>the equality predicate to use (default <code>(=)</code>)</p></dd></dl><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl><dl><dt class="spec value" id="val-find"><a href="#val-find" class="anchor"></a><code><span class="keyword">val</span> find : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> option</code></dt><dd><p>Find the first element on which the function doesn't return <code>None</code></p><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl><dl><dt class="spec value" id="val-find_map"><a href="#val-find_map" class="anchor"></a><code><span class="keyword">val</span> find_map : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> option</code></dt><dd><p>Alias to <a href="index.html#val-find"><code>find</code></a></p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-findi"><a href="#val-findi" class="anchor"></a><code><span class="keyword">val</span> findi : f:(int <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> option</code></dt><dd><p>Indexed version of <a href="index.html#val-find"><code>find</code></a></p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-find_mapi"><a href="#val-find_mapi" class="anchor"></a><code><span class="keyword">val</span> find_mapi : f:(int <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> option</code></dt><dd><p>Alias to <a href="index.html#val-findi"><code>findi</code></a></p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-find_pred"><a href="#val-find_pred" class="anchor"></a><code><span class="keyword">val</span> find_pred : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dd><p><code>find_pred p l</code> finds the first element of <code>l</code> that satisfies <code>p</code>, or returns <code>None</code> if no element satisfies <code>p</code></p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-find_pred_exn"><a href="#val-find_pred_exn" class="anchor"></a><code><span class="keyword">val</span> find_pred_exn : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Unsafe version of <a href="index.html#val-find_pred"><code>find_pred</code></a></p><dl><dt>raises Not_found</dt><dd><p>if no such element is found</p></dd></dl><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-length"><a href="#val-length" class="anchor"></a><code><span class="keyword">val</span> length : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p>How long is the sequence? Forces the sequence.</p></dd></dl><dl><dt class="spec value" id="val-is_empty"><a href="#val-is_empty" class="anchor"></a><code><span class="keyword">val</span> is_empty : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the sequence empty? Forces the sequence.</p></dd></dl></section><section><header><h3 id="transform-a-sequence"><a href="#transform-a-sequence" class="anchor"></a>Transform a sequence</h3></header><dl><dt class="spec value" id="val-filter"><a href="#val-filter" class="anchor"></a><code><span class="keyword">val</span> filter : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Filter on elements of the sequence</p></dd></dl><dl><dt class="spec value" id="val-append"><a href="#val-append" class="anchor"></a><code><span class="keyword">val</span> append : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Append two sequences. Iterating on the result is like iterating on the first, then on the second.</p></dd></dl><dl><dt class="spec value" id="val-append_l"><a href="#val-append_l" class="anchor"></a><code><span class="keyword">val</span> append_l : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> list <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Append sequences. Iterating on the result is like iterating on the each sequence of the list in order.</p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-concat"><a href="#val-concat" class="anchor"></a><code><span class="keyword">val</span> concat : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Concatenate a sequence of sequences into one sequence.</p></dd></dl><dl><dt class="spec value" id="val-flatten"><a href="#val-flatten" class="anchor"></a><code><span class="keyword">val</span> flatten : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Alias for <a href="index.html#val-concat"><code>concat</code></a></p></dd></dl><dl><dt class="spec value" id="val-flat_map"><a href="#val-flat_map" class="anchor"></a><code><span class="keyword">val</span> flat_map : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Alias to <code>flatMap</code> with a more explicit name</p></dd></dl><dl><dt class="spec value" id="val-flat_map_l"><a href="#val-flat_map_l" class="anchor"></a><code><span class="keyword">val</span> flat_map_l : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> list) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Convenience function combining <a href="index.html#val-flat_map"><code>flat_map</code></a> and <a href="index.html#val-of_list"><code>of_list</code></a></p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-filter_map"><a href="#val-filter_map" class="anchor"></a><code><span class="keyword">val</span> filter_map : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Alias to <code>fmap</code> with a more explicit name</p></dd></dl><dl><dt class="spec value" id="val-filter_mapi"><a href="#val-filter_mapi" class="anchor"></a><code><span class="keyword">val</span> filter_mapi : f:(int <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map with indices, and only keep non-<code>None</code> elements</p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-seq_list"><a href="#val-seq_list" class="anchor"></a><code><span class="keyword">val</span> seq_list : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> list <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p><code>seq_list l</code> returns all the ways to pick one element in each sub-sequence in <code>l</code>. Assumes the sub-sequences can be iterated on several times.</p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-seq_list_map"><a href="#val-seq_list_map" class="anchor"></a><code><span class="keyword">val</span> seq_list_map : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'a</span> list <span>&#45;&gt;</span> <span class="type-var">'b</span> list <a href="index.html#type-t">t</a></code></dt><dd><p><code>seq_list_map f l</code> maps <code>f</code> over every element of <code>l</code>, then calls <a href="index.html#val-seq_list"><code>seq_list</code></a></p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-filter_count"><a href="#val-filter_count" class="anchor"></a><code><span class="keyword">val</span> filter_count : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p>Count how many elements satisfy the given predicate</p><dl><dt>since</dt><dd>1.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-intersperse"><a href="#val-intersperse" class="anchor"></a><code><span class="keyword">val</span> intersperse : x:<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Insert the single element between every element of the sequence</p></dd></dl><dl><dt class="spec value" id="val-keep_some"><a href="#val-keep_some" class="anchor"></a><code><span class="keyword">val</span> keep_some : <span class="type-var">'a</span> option <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>filter_some l</code> retains only elements of the form <code>Some x</code>. Same as <code>filter_map (fun x-&gt;x)</code></p><dl><dt>since</dt><dd>1.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-keep_ok"><a href="#val-keep_ok" class="anchor"></a><code><span class="keyword">val</span> keep_ok : (<span class="type-var">'a</span>, <span class="type-var">_</span>) Result.result <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>keep_ok l</code> retains only elements of the form <code>Ok x</code>.</p><dl><dt>since</dt><dd>1.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-keep_error"><a href="#val-keep_error" class="anchor"></a><code><span class="keyword">val</span> keep_error : (<span class="type-var">_</span>, <span class="type-var">'e</span>) Result.result <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'e</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>keep_error l</code> retains only elements of the form <code>Error x</code>.</p><dl><dt>since</dt><dd>1.0</dd></dl></dd></dl></section><section><header><h3 id="caching"><a href="#caching" class="anchor"></a>Caching</h3></header><dl><dt class="spec value" id="val-persistent"><a href="#val-persistent" class="anchor"></a><code><span class="keyword">val</span> persistent : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Iterate on the sequence, storing elements in an efficient internal structure.. The resulting sequence can be iterated on as many times as needed. <b>Note</b>: calling persistent on an already persistent sequence will still make a new copy of the sequence!</p></dd></dl><dl><dt class="spec value" id="val-persistent_lazy"><a href="#val-persistent_lazy" class="anchor"></a><code><span class="keyword">val</span> persistent_lazy : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Lazy version of <a href="index.html#val-persistent"><code>persistent</code></a>. When calling <code>persistent_lazy s</code>, a new sequence <code>s'</code> is immediately returned (without actually consuming <code>s</code>) in constant time; the first time <code>s'</code> is iterated on, it also consumes <code>s</code> and caches its content into a inner data structure that will back <code>s'</code> for future iterations.</p><p><b>warning</b>: on the first traversal of <code>s'</code>, if the traversal is interrupted prematurely (<a href="index.html#val-take"><code>take</code></a>, etc.) then <code>s'</code> will not be memorized, and the next call to <code>s'</code> will traverse <code>s</code> again.</p></dd></dl></section><section><header><h3 id="misc"><a href="#misc" class="anchor"></a>Misc</h3></header><dl><dt class="spec value" id="val-sort"><a href="#val-sort" class="anchor"></a><code><span class="keyword">val</span> sort : ?&#8288;cmp:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> int) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sort the sequence. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument sequence immediately, before it sorts them.</p></dd></dl><dl><dt class="spec value" id="val-sort_uniq"><a href="#val-sort_uniq" class="anchor"></a><code><span class="keyword">val</span> sort_uniq : ?&#8288;cmp:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> int) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sort the sequence and remove duplicates. Eager, same as <code>sort</code></p></dd></dl><dl><dt class="spec value" id="val-sorted"><a href="#val-sorted" class="anchor"></a><code><span class="keyword">val</span> sorted : ?&#8288;cmp:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> int) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> bool</code></dt><dd><p>Checks whether the sequence is sorted. Eager, same as <a href="index.html#val-sort"><code>sort</code></a>.</p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-group_succ_by"><a href="#val-group_succ_by" class="anchor"></a><code><span class="keyword">val</span> group_succ_by : ?&#8288;eq:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p>Group equal consecutive elements. Formerly synonym to <code>group</code>.</p><dl><dt>since</dt><dd>0.6</dd></dl></dd></dl><dl><dt class="spec value" id="val-group_by"><a href="#val-group_by" class="anchor"></a><code><span class="keyword">val</span> group_by : ?&#8288;hash:(<span class="type-var">'a</span> <span>&#45;&gt;</span> int) <span>&#45;&gt;</span> ?&#8288;eq:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p>Group equal elements, disregarding their order of appearance. The result sequence is traversable as many times as required. precondition: for any <code>x</code> and <code>y</code>, if <code>eq x y</code> then <code>hash x=hash y</code> must hold.</p><dl><dt>since</dt><dd>0.6</dd></dl></dd></dl><dl><dt class="spec value" id="val-count"><a href="#val-count" class="anchor"></a><code><span class="keyword">val</span> count : ?&#8288;hash:(<span class="type-var">'a</span> <span>&#45;&gt;</span> int) <span>&#45;&gt;</span> ?&#8288;eq:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * int) <a href="index.html#type-t">t</a></code></dt><dd><p>Map each distinct element to its number of occurrences in the whole seq. Similar to <code>group_by seq |&gt; map (fun l-&gt;List.hd l, List.length l)</code></p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-uniq"><a href="#val-uniq" class="anchor"></a><code><span class="keyword">val</span> uniq : ?&#8288;eq:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Remove consecutive duplicate elements. Basically this is like <code>fun seq -&gt; map List.hd (group seq)</code>.</p></dd></dl><dl><dt class="spec value" id="val-product"><a href="#val-product" class="anchor"></a><code><span class="keyword">val</span> product : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>Cartesian product of the sequences. When calling <code>product a b</code>, the caller <b>MUST</b> ensure that <code>b</code> can be traversed as many times as required (several times), possibly by calling <a href="index.html#val-persistent"><code>persistent</code></a> on it beforehand.</p></dd></dl><dl><dt class="spec value" id="val-diagonal_l"><a href="#val-diagonal_l" class="anchor"></a><code><span class="keyword">val</span> diagonal_l : <span class="type-var">'a</span> list <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'a</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>All pairs of distinct positions of the list. <code>diagonal l</code> will return the sequence of all <code>List.nth i l, List.nth j l</code> if <code>i &lt; j</code>.</p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-diagonal"><a href="#val-diagonal" class="anchor"></a><code><span class="keyword">val</span> diagonal : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'a</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>All pairs of distinct positions of the sequence. Iterates only once on the sequence, which must be finite.</p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-join"><a href="#val-join" class="anchor"></a><code><span class="keyword">val</span> join : join_row:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>join ~join_row a b</code> combines every element of <code>a</code> with every element of <code>b</code> using <code>join_row</code>. If <code>join_row</code> returns None, then the two elements do not combine. Assume that <code>b</code> allows for multiple iterations.</p></dd></dl><dl><dt class="spec value" id="val-join_by"><a href="#val-join_by" class="anchor"></a><code><span class="keyword">val</span> join_by : ?&#8288;eq:<span class="type-var">'key</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'key</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'key</span>) <span>&#45;&gt;</span> (<span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'key</span>) <span>&#45;&gt;</span> merge:(<span class="type-var">'key</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>join key1 key2 ~merge</code> is a binary operation that takes two sequences <code>a</code> and <code>b</code>, projects their elements resp. with <code>key1</code> and <code>key2</code>, and combine values <code>(x,y)</code> from <code>(a,b)</code> with the same <code>key</code> using <code>merge</code>. If <code>merge</code> returns <code>None</code>, the combination of values is discarded. precondition: for any <code>x</code> and <code>y</code>, if <code>eq x y</code> then <code>hash x=hash y</code> must hold.</p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-join_all_by"><a href="#val-join_all_by" class="anchor"></a><code><span class="keyword">val</span> join_all_by : ?&#8288;eq:<span class="type-var">'key</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'key</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'key</span>) <span>&#45;&gt;</span> (<span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'key</span>) <span>&#45;&gt;</span> merge:(<span class="type-var">'key</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <span>&#45;&gt;</span> <span class="type-var">'b</span> list <span>&#45;&gt;</span> <span class="type-var">'c</span> option) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>join_all_by key1 key2 ~merge</code> is a binary operation that takes two sequences <code>a</code> and <code>b</code>, projects their elements resp. with <code>key1</code> and <code>key2</code>, and, for each key <code>k</code> occurring in at least one of them:</p><ul><li>compute the list <code>l1</code> of elements of <code>a</code> that map to <code>k</code></li><li>compute the list <code>l2</code> of elements of <code>b</code> that map to <code>k</code></li><li>call <code>merge k l1 l2</code>. If <code>merge</code> returns <code>None</code>, the combination of values is discarded, otherwise it returns <code>Some c</code> and <code>c</code> is inserted in the result.</li></ul><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-group_join_by"><a href="#val-group_join_by" class="anchor"></a><code><span class="keyword">val</span> group_join_by : ?&#8288;eq:<span class="type-var">'a</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'a</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> (<span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span> list) <a href="index.html#type-t">t</a></code></dt><dd><p><code>group_join_by key2</code> associates to every element <code>x</code> of the first sequence, all the elements <code>y</code> of the second sequence such that <code>eq x (key y)</code>. Elements of the first sequences without corresponding values in the second one are mapped to <code>[]</code> precondition: for any <code>x</code> and <code>y</code>, if <code>eq x y</code> then <code>hash x=hash y</code> must hold.</p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-inter"><a href="#val-inter" class="anchor"></a><code><span class="keyword">val</span> inter : ?&#8288;eq:<span class="type-var">'a</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'a</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any <code>x</code> and <code>y</code>, if <code>eq x y</code> then <code>hash x=hash y</code> must hold.</p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-union"><a href="#val-union" class="anchor"></a><code><span class="keyword">val</span> union : ?&#8288;eq:<span class="type-var">'a</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'a</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any <code>x</code> and <code>y</code>, if <code>eq x y</code> then <code>hash x=hash y</code> must hold.</p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-diff"><a href="#val-diff" class="anchor"></a><code><span class="keyword">val</span> diff : ?&#8288;eq:<span class="type-var">'a</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'a</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Set difference. Eager.</p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-subset"><a href="#val-subset" class="anchor"></a><code><span class="keyword">val</span> subset : ?&#8288;eq:<span class="type-var">'a</span> <a href="index.html#type-equal">equal</a> <span>&#45;&gt;</span> ?&#8288;hash:<span class="type-var">'a</span> <a href="index.html#type-hash">hash</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> bool</code></dt><dd><p><code>subset a b</code> returns <code>true</code> if all elements of <code>a</code> belong to <code>b</code>. Eager. precondition: for any <code>x</code> and <code>y</code>, if <code>eq x y</code> then <code>hash x=hash y</code> must hold.</p><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-unfoldr"><a href="#val-unfoldr" class="anchor"></a><code><span class="keyword">val</span> unfoldr : (<span class="type-var">'b</span> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) option) <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>unfoldr f b</code> will apply <code>f</code> to <code>b</code>. If it yields <code>Some (x,b')</code> then <code>x</code> is returned and unfoldr recurses with <code>b'</code>.</p></dd></dl><dl><dt class="spec value" id="val-scan"><a href="#val-scan" class="anchor"></a><code><span class="keyword">val</span> scan : (<span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence of intermediate results</p></dd></dl><dl><dt class="spec value" id="val-max"><a href="#val-max" class="anchor"></a><code><span class="keyword">val</span> max : ?&#8288;lt:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dd><p>Max element of the sequence, using the given comparison function.</p><dl><dt>returns</dt><dd><p>None if the sequence is empty, Some <code>m</code> where <code>m</code> is the maximal element otherwise</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-max_exn"><a href="#val-max_exn" class="anchor"></a><code><span class="keyword">val</span> max_exn : ?&#8288;lt:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Unsafe version of <a href="index.html#val-max"><code>max</code></a></p><dl><dt>raises Not_found</dt><dd><p>if the sequence is empty</p></dd></dl><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-min"><a href="#val-min" class="anchor"></a><code><span class="keyword">val</span> min : ?&#8288;lt:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dd><p>Min element of the sequence, using the given comparison function. see <a href="index.html#val-max"><code>max</code></a> for more details.</p></dd></dl><dl><dt class="spec value" id="val-min_exn"><a href="#val-min_exn" class="anchor"></a><code><span class="keyword">val</span> min_exn : ?&#8288;lt:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Unsafe version of <a href="index.html#val-min"><code>min</code></a></p><dl><dt>raises Not_found</dt><dd><p>if the sequence is empty</p></dd></dl><dl><dt>since</dt><dd>0.10</dd></dl></dd></dl><dl><dt class="spec value" id="val-sum"><a href="#val-sum" class="anchor"></a><code><span class="keyword">val</span> sum : int <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p>Sum of elements</p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-sumf"><a href="#val-sumf" class="anchor"></a><code><span class="keyword">val</span> sumf : float <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> float</code></dt><dd><p>Sum of elements, using Kahan summation</p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-head"><a href="#val-head" class="anchor"></a><code><span class="keyword">val</span> head : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dd><p>First element, if any, otherwise <code>None</code></p><dl><dt>since</dt><dd>0.5.1</dd></dl></dd></dl><dl><dt class="spec value" id="val-head_exn"><a href="#val-head_exn" class="anchor"></a><code><span class="keyword">val</span> head_exn : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>First element, if any, fails</p><dl><dt>raises Invalid_argument</dt><dd><p>if the sequence is empty</p></dd></dl><dl><dt>since</dt><dd>0.5.1</dd></dl></dd></dl><dl><dt class="spec value" id="val-take"><a href="#val-take" class="anchor"></a><code><span class="keyword">val</span> take : int <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Take at most <code>n</code> elements from the sequence. Works on infinite sequences.</p></dd></dl><dl><dt class="spec value" id="val-take_while"><a href="#val-take_while" class="anchor"></a><code><span class="keyword">val</span> take_while : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite sequence <code>s</code> if the predicate is false for at least one element of <code>s</code>.</p></dd></dl><dl><dt class="spec value" id="val-fold_while"><a href="#val-fold_while" class="anchor"></a><code><span class="keyword">val</span> fold_while : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> * [ `Stop | `Continue ]) <span>&#45;&gt;</span> init:<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Folds over elements of the sequence, stopping early if the accumulator returns <code>('a, `Stop)</code></p><dl><dt>since</dt><dd>0.5.5</dd></dl></dd></dl><dl><dt class="spec value" id="val-drop"><a href="#val-drop" class="anchor"></a><code><span class="keyword">val</span> drop : int <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Drop the <code>n</code> first elements of the sequence. Lazy.</p></dd></dl><dl><dt class="spec value" id="val-drop_while"><a href="#val-drop_while" class="anchor"></a><code><span class="keyword">val</span> drop_while : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Predicate version of <a href="index.html#val-drop"><code>drop</code></a></p></dd></dl><dl><dt class="spec value" id="val-rev"><a href="#val-rev" class="anchor"></a><code><span class="keyword">val</span> rev : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Reverse the sequence. O(n) memory and time, needs the sequence to be finite. The result is persistent and does not depend on the input being repeatable.</p></dd></dl><dl><dt class="spec value" id="val-zip_i"><a href="#val-zip_i" class="anchor"></a><code><span class="keyword">val</span> zip_i : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (int * <span class="type-var">'a</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>Zip elements of the sequence with their index in the sequence. Changed type </p><dl><dt>since</dt><dd>1.0 to just give a sequence of pairs</dd></dl></dd></dl><dl><dt class="spec value" id="val-fold2"><a href="#val-fold2" class="anchor"></a><code><span class="keyword">val</span> fold2 : f:(<span class="type-var">'c</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span>) <span>&#45;&gt;</span> init:<span class="type-var">'c</span> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span></code></dt><dt class="spec value" id="val-iter2"><a href="#val-iter2" class="anchor"></a><code><span class="keyword">val</span> iter2 : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dt class="spec value" id="val-map2"><a href="#val-map2" class="anchor"></a><code><span class="keyword">val</span> map2 : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span>) <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-map2_2"><a href="#val-map2_2" class="anchor"></a><code><span class="keyword">val</span> map2_2 : f:(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span>) <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'d</span>) <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'c</span> * <span class="type-var">'d</span>) <a href="index.html#type-t">t</a></code></dt><dd><p><code>map2_2 f g seq2</code> maps each <code>x, y</code> of seq2 into <code>f x y, g x y</code></p></dd></dl></section><section><header><h3 id="basic-data-structures-converters"><a href="#basic-data-structures-converters" class="anchor"></a>Basic data structures converters</h3></header><dl><dt class="spec value" id="val-to_list"><a href="#val-to_list" class="anchor"></a><code><span class="keyword">val</span> to_list : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list</code></dt><dd><p>Convert the sequence into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider <a href="index.html#val-to_rev_list"><code>to_rev_list</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-to_rev_list"><a href="#val-to_rev_list" class="anchor"></a><code><span class="keyword">val</span> to_rev_list : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list</code></dt><dd><p>Get the list of the reversed sequence (more efficient than <a href="index.html#val-to_list"><code>to_list</code></a>)</p></dd></dl><dl><dt class="spec value" id="val-of_list"><a href="#val-of_list" class="anchor"></a><code><span class="keyword">val</span> of_list : <span class="type-var">'a</span> list <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-on_list"><a href="#val-on_list" class="anchor"></a><code><span class="keyword">val</span> on_list : (<span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'a</span> list <span>&#45;&gt;</span> <span class="type-var">'b</span> list</code></dt><dd><p><code>on_list f l</code> is equivalent to <code>to_list @@ f @@ of_list l</code>.</p><dl><dt>since</dt><dd>0.5.2</dd></dl></dd></dl><dl><dt class="spec value" id="val-pair_with_idx"><a href="#val-pair_with_idx" class="anchor"></a><code><span class="keyword">val</span> pair_with_idx : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (int * <span class="type-var">'a</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>Similar to <a href="index.html#val-zip_i"><code>zip_i</code></a> but returns a normal sequence of tuples</p><dl><dt>since</dt><dd>0.11</dd></dl></dd></dl><dl><dt class="spec value" id="val-to_opt"><a href="#val-to_opt" class="anchor"></a><code><span class="keyword">val</span> to_opt : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dd><p>Alias to <a href="index.html#val-head"><code>head</code></a></p><dl><dt>since</dt><dd>0.5.1</dd></dl></dd></dl><dl><dt class="spec value" id="val-to_array"><a href="#val-to_array" class="anchor"></a><code><span class="keyword">val</span> to_array : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> array</code></dt><dd><p>Convert to an array. Currently not very efficient because an intermediate list is used.</p></dd></dl><dl><dt class="spec value" id="val-of_array"><a href="#val-of_array" class="anchor"></a><code><span class="keyword">val</span> of_array : <span class="type-var">'a</span> array <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-of_array_i"><a href="#val-of_array_i" class="anchor"></a><code><span class="keyword">val</span> of_array_i : <span class="type-var">'a</span> array <span>&#45;&gt;</span> (int * <span class="type-var">'a</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>Elements of the array, with their index</p></dd></dl><dl><dt class="spec value" id="val-array_slice"><a href="#val-array_slice" class="anchor"></a><code><span class="keyword">val</span> array_slice : <span class="type-var">'a</span> array <span>&#45;&gt;</span> int <span>&#45;&gt;</span> int <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>array_slice a i j</code> Sequence of elements whose indexes range from <code>i</code> to <code>j</code></p></dd></dl><dl><dt class="spec value" id="val-of_opt"><a href="#val-of_opt" class="anchor"></a><code><span class="keyword">val</span> of_opt : <span class="type-var">'a</span> option <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Iterate on 0 or 1 values.</p><dl><dt>since</dt><dd>0.5.1</dd></dl></dd></dl><dl><dt class="spec value" id="val-of_stream"><a href="#val-of_stream" class="anchor"></a><code><span class="keyword">val</span> of_stream : <span class="type-var">'a</span> Stream.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence of elements of a stream (usable only once)</p></dd></dl><dl><dt class="spec value" id="val-to_stream"><a href="#val-to_stream" class="anchor"></a><code><span class="keyword">val</span> to_stream : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> Stream.t</code></dt><dd><p>Convert to a stream. linear in memory and time (a copy is made in memory)</p></dd></dl><dl><dt class="spec value" id="val-to_stack"><a href="#val-to_stack" class="anchor"></a><code><span class="keyword">val</span> to_stack : <span class="type-var">'a</span> Stack.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Push elements of the sequence on the stack</p></dd></dl><dl><dt class="spec value" id="val-of_stack"><a href="#val-of_stack" class="anchor"></a><code><span class="keyword">val</span> of_stack : <span class="type-var">'a</span> Stack.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence of elements of the stack (same order as <code>Stack.iter</code>)</p></dd></dl><dl><dt class="spec value" id="val-to_queue"><a href="#val-to_queue" class="anchor"></a><code><span class="keyword">val</span> to_queue : <span class="type-var">'a</span> Queue.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Push elements of the sequence into the queue</p></dd></dl><dl><dt class="spec value" id="val-of_queue"><a href="#val-of_queue" class="anchor"></a><code><span class="keyword">val</span> of_queue : <span class="type-var">'a</span> Queue.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence of elements contained in the queue, FIFO order</p></dd></dl><dl><dt class="spec value" id="val-hashtbl_add"><a href="#val-hashtbl_add" class="anchor"></a><code><span class="keyword">val</span> hashtbl_add : (<span class="type-var">'a</span>, <span class="type-var">'b</span>) Hashtbl.t <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Add elements of the sequence to the hashtable, with Hashtbl.add</p></dd></dl><dl><dt class="spec value" id="val-hashtbl_replace"><a href="#val-hashtbl_replace" class="anchor"></a><code><span class="keyword">val</span> hashtbl_replace : (<span class="type-var">'a</span>, <span class="type-var">'b</span>) Hashtbl.t <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Add elements of the sequence to the hashtable, with Hashtbl.replace (erases conflicting bindings)</p></dd></dl><dl><dt class="spec value" id="val-to_hashtbl"><a href="#val-to_hashtbl" class="anchor"></a><code><span class="keyword">val</span> to_hashtbl : (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span>, <span class="type-var">'b</span>) Hashtbl.t</code></dt><dd><p>Build a hashtable from a sequence of key/value pairs</p></dd></dl><dl><dt class="spec value" id="val-of_hashtbl"><a href="#val-of_hashtbl" class="anchor"></a><code><span class="keyword">val</span> of_hashtbl : (<span class="type-var">'a</span>, <span class="type-var">'b</span>) Hashtbl.t <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence of key/value pairs from the hashtable</p></dd></dl><dl><dt class="spec value" id="val-hashtbl_keys"><a href="#val-hashtbl_keys" class="anchor"></a><code><span class="keyword">val</span> hashtbl_keys : (<span class="type-var">'a</span>, <span class="type-var">'b</span>) Hashtbl.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-hashtbl_values"><a href="#val-hashtbl_values" class="anchor"></a><code><span class="keyword">val</span> hashtbl_values : (<span class="type-var">'a</span>, <span class="type-var">'b</span>) Hashtbl.t <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-of_str"><a href="#val-of_str" class="anchor"></a><code><span class="keyword">val</span> of_str : string <span>&#45;&gt;</span> char <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-to_str"><a href="#val-to_str" class="anchor"></a><code><span class="keyword">val</span> to_str : char <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dt class="spec value" id="val-concat_str"><a href="#val-concat_str" class="anchor"></a><code><span class="keyword">val</span> concat_str : string <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dd><p>Concatenate strings together, eagerly. Also see <a href="index.html#val-intersperse"><code>intersperse</code></a> to add a separator.</p><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl><dl><dt class="spec exception" id="exception-OneShotSequence"><a href="#exception-OneShotSequence" class="anchor"></a><code><span class="keyword">exception</span> </code><code><span class="exception">OneShotSequence</span></code></dt><dd><p>Raised when the user tries to iterate several times on a transient iterator</p></dd></dl><dl><dt class="spec value" id="val-of_in_channel"><a href="#val-of_in_channel" class="anchor"></a><code><span class="keyword">val</span> of_in_channel : Pervasives.in_channel <span>&#45;&gt;</span> char <a href="index.html#type-t">t</a></code></dt><dd><p>Iterates on characters of the input (can block when one iterates over the sequence). If you need to iterate several times on this sequence, use <a href="index.html#val-persistent"><code>persistent</code></a>.</p><dl><dt>raises OneShotSequence</dt><dd><p>when used more than once.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-to_buffer"><a href="#val-to_buffer" class="anchor"></a><code><span class="keyword">val</span> to_buffer : char <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> Buffer.t <span>&#45;&gt;</span> unit</code></dt><dd><p>Copy content of the sequence into the buffer</p></dd></dl><dl><dt class="spec value" id="val-int_range"><a href="#val-int_range" class="anchor"></a><code><span class="keyword">val</span> int_range : start:int <span>&#45;&gt;</span> stop:int <span>&#45;&gt;</span> int <a href="index.html#type-t">t</a></code></dt><dd><p>Iterator on integers in <code>start...stop</code> by steps 1. Also see <a href="index.html#val-(--)"><code>(--)</code></a> for an infix version.</p></dd></dl><dl><dt class="spec value" id="val-int_range_dec"><a href="#val-int_range_dec" class="anchor"></a><code><span class="keyword">val</span> int_range_dec : start:int <span>&#45;&gt;</span> stop:int <span>&#45;&gt;</span> int <a href="index.html#type-t">t</a></code></dt><dd><p>Iterator on decreasing integers in <code>stop...start</code> by steps -1. See <a href="index.html#val-(--^)"><code>(--^)</code></a> for an infix version</p></dd></dl><dl><dt class="spec value" id="val-int_range_by"><a href="#val-int_range_by" class="anchor"></a><code><span class="keyword">val</span> int_range_by : step:int <span>&#45;&gt;</span> start:int <span>&#45;&gt;</span> stop:int <span>&#45;&gt;</span> int <a href="index.html#type-t">t</a></code></dt><dd><p><code>int_range_by ~step ~start:i ~stop:j</code> is the range starting at <code>i</code>, including <code>j</code>, where the difference between successive elements is <code>step</code>. use a negative <code>step</code> for a decreasing sequence.</p><dl><dt>since</dt><dd>0.9</dd></dl><dl><dt>raises Invalid_argument</dt><dd><p>if <code>step=0</code></p></dd></dl></dd></dl><dl><dt class="spec value" id="val-bools"><a href="#val-bools" class="anchor"></a><code><span class="keyword">val</span> bools : bool <a href="index.html#type-t">t</a></code></dt><dd><p>Iterates on <code>true</code> and <code>false</code></p><dl><dt>since</dt><dd>0.9</dd></dl></dd></dl><dl><dt class="spec value" id="val-of_set"><a href="#val-of_set" class="anchor"></a><code><span class="keyword">val</span> of_set : (<span class="keyword">module</span> Set.S <span class="keyword">with</span> <span class="keyword">type</span> elt = <span class="type-var">'a</span> <span class="keyword">and</span> <span class="keyword">type</span> t = <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Convert the given set to a sequence. The set module must be provided.</p></dd></dl><dl><dt class="spec value" id="val-to_set"><a href="#val-to_set" class="anchor"></a><code><span class="keyword">val</span> to_set : (<span class="keyword">module</span> Set.S <span class="keyword">with</span> <span class="keyword">type</span> elt = <span class="type-var">'a</span> <span class="keyword">and</span> <span class="keyword">type</span> t = <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span></code></dt><dd><p>Convert the sequence to a set, given the proper set module</p></dd></dl><dl><dt class="spec type" id="type-gen"><a href="#type-gen" class="anchor"></a><code><span class="keyword">type</span> 'a gen</code><code> = unit <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dt class="spec type" id="type-klist"><a href="#type-klist" class="anchor"></a><code><span class="keyword">type</span> 'a klist</code><code> = unit <span>&#45;&gt;</span> [ `Nil | `Cons of <span class="type-var">'a</span> * <span class="type-var">'a</span> <a href="index.html#type-klist">klist</a> ]</code></dt></dl><dl><dt class="spec value" id="val-of_gen"><a href="#val-of_gen" class="anchor"></a><code><span class="keyword">val</span> of_gen : <span class="type-var">'a</span> <a href="index.html#type-gen">gen</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Traverse eagerly the generator and build a sequence from it</p></dd></dl><dl><dt class="spec value" id="val-to_gen"><a href="#val-to_gen" class="anchor"></a><code><span class="keyword">val</span> to_gen : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-gen">gen</a></code></dt><dd><p>Make the sequence persistent (O(n)) and then iterate on it. Eager.</p></dd></dl><dl><dt class="spec value" id="val-of_klist"><a href="#val-of_klist" class="anchor"></a><code><span class="keyword">val</span> of_klist : <span class="type-var">'a</span> <a href="index.html#type-klist">klist</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Iterate on the lazy list</p></dd></dl><dl><dt class="spec value" id="val-to_klist"><a href="#val-to_klist" class="anchor"></a><code><span class="keyword">val</span> to_klist : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-klist">klist</a></code></dt><dd><p>Make the sequence persistent and then iterate on it. Eager.</p></dd></dl></section><section><header><h3 id="functorial-conversions-between-sets-and-sequences"><a href="#functorial-conversions-between-sets-and-sequences" class="anchor"></a>Functorial conversions between sets and sequences</h3></header><div class="spec module" id="module-Set"><a href="#module-Set" class="anchor"></a><code><span class="keyword">module</span> <a href="Set/index.html">Set</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div></section><section><header><h3 id="conversion-between-maps-and-sequences."><a href="#conversion-between-maps-and-sequences." class="anchor"></a>Conversion between maps and sequences.</h3></header><div class="spec module" id="module-Map"><a href="#module-Map" class="anchor"></a><code><span class="keyword">module</span> <a href="Map/index.html">Map</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div></section><section><header><h3 id="infinite-sequences-of-random-values"><a href="#infinite-sequences-of-random-values" class="anchor"></a>Infinite sequences of random values</h3></header><dl><dt class="spec value" id="val-random_int"><a href="#val-random_int" class="anchor"></a><code><span class="keyword">val</span> random_int : int <span>&#45;&gt;</span> int <a href="index.html#type-t">t</a></code></dt><dd><p>Infinite sequence of random integers between 0 and the given higher bound (see Random.int)</p></dd></dl><dl><dt class="spec value" id="val-random_bool"><a href="#val-random_bool" class="anchor"></a><code><span class="keyword">val</span> random_bool : bool <a href="index.html#type-t">t</a></code></dt><dd><p>Infinite sequence of random bool values</p></dd></dl><dl><dt class="spec value" id="val-random_float"><a href="#val-random_float" class="anchor"></a><code><span class="keyword">val</span> random_float : float <span>&#45;&gt;</span> float <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-random_array"><a href="#val-random_array" class="anchor"></a><code><span class="keyword">val</span> random_array : <span class="type-var">'a</span> array <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Sequence of choices of an element in the array</p></dd></dl><dl><dt class="spec value" id="val-random_list"><a href="#val-random_list" class="anchor"></a><code><span class="keyword">val</span> random_list : <span class="type-var">'a</span> list <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Infinite sequence of random elements of the list. Basically the same as <a href="index.html#val-random_array"><code>random_array</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-shuffle"><a href="#val-shuffle" class="anchor"></a><code><span class="keyword">val</span> shuffle : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>shuffle seq</code> returns a perfect shuffle of <code>seq</code>. Uses O(length seq) memory and time. Eager.</p><dl><dt>since</dt><dd>0.7</dd></dl></dd></dl><dl><dt class="spec value" id="val-shuffle_buffer"><a href="#val-shuffle_buffer" class="anchor"></a><code><span class="keyword">val</span> shuffle_buffer : n:int <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>shuffle_buffer n seq</code> returns a sequence of element of <code>seq</code> in random order. The shuffling is not uniform. Uses O(n) memory.</p><p>The first <code>n</code> elements of the sequence are consumed immediately. The rest is consumed lazily.</p><dl><dt>since</dt><dd>0.7</dd></dl></dd></dl></section><section><header><h3 id="sampling"><a href="#sampling" class="anchor"></a>Sampling</h3></header><dl><dt class="spec value" id="val-sample"><a href="#val-sample" class="anchor"></a><code><span class="keyword">val</span> sample : n:int <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> array</code></dt><dd><p><code>sample n seq</code> returns k samples of <code>seq</code>, with uniform probability. It will consume the sequence and use O(n) memory.</p><p>It returns an array of size <code>min (length seq) n</code>.</p><dl><dt>since</dt><dd>0.7</dd></dl></dd></dl></section><section><header><h3 id="infix-functions"><a href="#infix-functions" class="anchor"></a>Infix functions</h3></header><div class="spec module" id="module-Infix"><a href="#module-Infix" class="anchor"></a><code><span class="keyword">module</span> <a href="Infix/index.html">Infix</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div><div><div class="spec include"><div class="doc"><details open="open"><summary><span class="def"><code><span class="keyword">include</span> <span class="keyword">module</span> <span class="keyword">type</span> <span class="keyword">of</span> <a href="index.html#module-Infix">Infix</a></code></span></summary><dl><dt class="spec value" id="val-(--)"><a href="#val-(--)" class="anchor"></a><code><span class="keyword">val</span> (--) : int <span>&#45;&gt;</span> int <span>&#45;&gt;</span> int <a href="index.html#type-t">t</a></code></dt><dd><p><code>a -- b</code> is the range of integers from <code>a</code> to <code>b</code>, both included, in increasing order. It will therefore be empty if <code>a &gt; b</code>.</p></dd></dl><dl><dt class="spec value" id="val-(--^)"><a href="#val-(--^)" class="anchor"></a><code><span class="keyword">val</span> (--^) : int <span>&#45;&gt;</span> int <span>&#45;&gt;</span> int <a href="index.html#type-t">t</a></code></dt><dd><p><code>a --^ b</code> is the range of integers from <code>b</code> to <code>a</code>, both included, in decreasing order (starts from <code>a</code>). It will therefore be empty if <code>a &lt; b</code>.</p></dd></dl><dl><dt class="spec value" id="val-(&gt;&gt;=)"><a href="#val-(&gt;&gt;=)" class="anchor"></a><code><span class="keyword">val</span> (&gt;&gt;=) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Monadic bind (infix version of <a href="index.html#val-flat_map"><code>flat_map</code></a></p><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl><dl><dt class="spec value" id="val-(&gt;|=)"><a href="#val-(&gt;|=)" class="anchor"></a><code><span class="keyword">val</span> (&gt;|=) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Infix version of <a href="index.html#val-map"><code>map</code></a></p><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl><dl><dt class="spec value" id="val-(&lt;*&gt;)"><a href="#val-(&lt;*&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&lt;*&gt;) : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Applicative operator (product+application)</p><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl><dl><dt class="spec value" id="val-(&lt;+&gt;)"><a href="#val-(&lt;+&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&lt;+&gt;) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Concatenation of sequences</p><dl><dt>since</dt><dd>0.5</dd></dl></dd></dl></details></div></div></div></section><section><header><h3 id="pretty-printing-of-sequences"><a href="#pretty-printing-of-sequences" class="anchor"></a>Pretty printing of sequences</h3></header><dl><dt class="spec value" id="val-pp_seq"><a href="#val-pp_seq" class="anchor"></a><code><span class="keyword">val</span> pp_seq : ?&#8288;sep:string <span>&#45;&gt;</span> (Format.formatter <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> Format.formatter <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Pretty print a sequence of <code>'a</code>, using the given pretty printer to print each elements. An optional separator string can be provided.</p></dd></dl><dl><dt class="spec value" id="val-pp_buf"><a href="#val-pp_buf" class="anchor"></a><code><span class="keyword">val</span> pp_buf : ?&#8288;sep:string <span>&#45;&gt;</span> (Buffer.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> Buffer.t <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Print into a buffer</p></dd></dl><dl><dt class="spec value" id="val-to_string"><a href="#val-to_string" class="anchor"></a><code><span class="keyword">val</span> to_string : ?&#8288;sep:string <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> string) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dd><p>Print into a string</p></dd></dl></section><section><header><h3 id="basic-io"><a href="#basic-io" class="anchor"></a>Basic IO</h3><p>Very basic interface to manipulate files as sequence of chunks/lines. The sequences take care of opening and closing files properly; every time one iterates over a sequence, the file is opened/closed again.</p><p>Example: copy a file <code>&quot;a&quot;</code> into file <code>&quot;b&quot;</code>, removing blank lines:</p><pre><code class="ml">Sequence.(IO.lines_of &quot;a&quot; |&gt; filter (fun l-&gt; l&lt;&gt; &quot;&quot;) |&gt; IO.write_lines &quot;b&quot;);;</code></pre><p>By chunks of <code>4096</code> bytes:</p><pre><code class="ml">Sequence.IO.(chunks_of ~size:4096 &quot;a&quot; |&gt; write_to &quot;b&quot;);;</code></pre><p>Read the lines of a file into a list:</p><pre><code class="ml">Sequence.IO.lines &quot;a&quot; |&gt; Sequence.to_list</code></pre><dl><dt>since</dt><dd>0.5.1</dd></dl></header><div class="spec module" id="module-IO"><a href="#module-IO" class="anchor"></a><code><span class="keyword">module</span> <a href="IO/index.html">IO</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div></section></div></body></html>