ocaml-containers/0.21/CCLinq.html
2016-11-03 16:14:53 +01:00

442 lines
No EOL
34 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="previous" href="Containers_advanced.html">
<link rel="next" href="CCBatch.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of class methods" rel=Appendix href="index_methods.html">
<link title="Index of class types" rel=Appendix href="index_class_types.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="CCVector" rel="Chapter" href="CCVector.html">
<link title="CCPrint" rel="Chapter" href="CCPrint.html">
<link title="CCError" rel="Chapter" href="CCError.html">
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
<link title="CCList" rel="Chapter" href="CCList.html">
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
<link title="CCPair" rel="Chapter" href="CCPair.html">
<link title="CCFun" rel="Chapter" href="CCFun.html">
<link title="CCHash" rel="Chapter" href="CCHash.html">
<link title="CCInt" rel="Chapter" href="CCInt.html">
<link title="CCBool" rel="Chapter" href="CCBool.html">
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
<link title="CCArray" rel="Chapter" href="CCArray.html">
<link title="CCRef" rel="Chapter" href="CCRef.html">
<link title="CCSet" rel="Chapter" href="CCSet.html">
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
<link title="CCString" rel="Chapter" href="CCString.html">
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
<link title="CCMap" rel="Chapter" href="CCMap.html">
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
<link title="CCIO" rel="Chapter" href="CCIO.html">
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
<link title="CCChar" rel="Chapter" href="CCChar.html">
<link title="CCResult" rel="Chapter" href="CCResult.html">
<link title="Containers" rel="Chapter" href="Containers.html">
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
<link title="CCKList" rel="Chapter" href="CCKList.html">
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
<link title="CCCache" rel="Chapter" href="CCCache.html">
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
<link title="CCBV" rel="Chapter" href="CCBV.html">
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
<link title="CCHashconsedSet" rel="Chapter" href="CCHashconsedSet.html">
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
<link title="CCBloom" rel="Chapter" href="CCBloom.html">
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
<link title="CCAllocCache" rel="Chapter" href="CCAllocCache.html">
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
<link title="CCHet" rel="Chapter" href="CCHet.html">
<link title="Containers_string" rel="Chapter" href="Containers_string.html">
<link title="CCKMP" rel="Chapter" href="CCKMP.html">
<link title="CCLevenshtein" rel="Chapter" href="CCLevenshtein.html">
<link title="CCApp_parse" rel="Chapter" href="CCApp_parse.html">
<link title="CCParse" rel="Chapter" href="CCParse.html">
<link title="CCBigstring" rel="Chapter" href="CCBigstring.html">
<link title="CCArray1" rel="Chapter" href="CCArray1.html">
<link title="CCPool" rel="Chapter" href="CCPool.html">
<link title="CCLock" rel="Chapter" href="CCLock.html">
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
<link title="CCThread" rel="Chapter" href="CCThread.html">
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
<link title="Containers_advanced" rel="Chapter" href="Containers_advanced.html">
<link title="CCLinq" rel="Chapter" href="CCLinq.html">
<link title="CCBatch" rel="Chapter" href="CCBatch.html">
<link title="CCCat" rel="Chapter" href="CCCat.html">
<link title="CCMonadIO" rel="Chapter" href="CCMonadIO.html">
<link title="Containers_io_is_deprecated" rel="Chapter" href="Containers_io_is_deprecated.html">
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
<link title="CCSexpM" rel="Chapter" href="CCSexpM.html"><link title="Query operators" rel="Section" href="#2_Queryoperators">
<link title="Initial values" rel="Subsection" href="#6_Initialvalues">
<link title="Execution" rel="Subsection" href="#6_Execution">
<link title="Basics" rel="Subsection" href="#6_Basics">
<link title="Aggregation" rel="Subsection" href="#6_Aggregation">
<link title="Binary Operators" rel="Subsection" href="#6_BinaryOperators">
<link title="Tuple and Options" rel="Subsection" href="#6_TupleandOptions">
<link title="Tuple and Options" rel="Subsection" href="#6_TupleandOptions">
<link title="Applicative" rel="Subsection" href="#6_Applicative">
<link title="Monad" rel="Subsection" href="#6_Monad">
<link title="Misc" rel="Subsection" href="#6_Misc">
<link title="Infix" rel="Subsection" href="#6_Infix">
<link title="Adapters" rel="Subsection" href="#6_Adapters">
<title>Containers doc : CCLinq</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Containers_advanced.html" title="Containers_advanced">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="CCBatch.html" title="CCBatch">Next</a>
</div>
<h1>Module <a href="type_CCLinq.html">CCLinq</a></h1>
<pre><span class="keyword">module</span> CCLinq: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<span class="warning">Deprecated.</span>use <a href=" https://github.com/c-cube/olinq"> OLinq</a>
<p>
<pre class="codepre"><code class="code"><span class="constructor">CCLinq</span>.(<br>
&nbsp;&nbsp;of_list&nbsp;[1;2;3]<br>
&nbsp;&nbsp;|&gt;&nbsp;flat_map&nbsp;(<span class="keyword">fun</span>&nbsp;x&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="constructor">Sequence</span>.(x&nbsp;--&nbsp;(x+10)))<br>
&nbsp;&nbsp;|&gt;&nbsp;sort&nbsp;()<br>
&nbsp;&nbsp;|&gt;&nbsp;count&nbsp;()<br>
&nbsp;&nbsp;|&gt;&nbsp;flat_map&nbsp;<span class="constructor">PMap</span>.to_seq<br>
&nbsp;&nbsp;|&gt;&nbsp;<span class="constructor">List</span>.run<br>
);;<br>
-&nbsp;:&nbsp;(int&nbsp;*&nbsp;int)&nbsp;list&nbsp;=&nbsp;[(13,&nbsp;1);&nbsp;(12,&nbsp;2);&nbsp;(11,&nbsp;3);&nbsp;(10,&nbsp;3);&nbsp;(9,&nbsp;3);<br>
&nbsp;&nbsp;&nbsp;&nbsp;(8,&nbsp;3);&nbsp;(7,&nbsp;3);&nbsp;(6,&nbsp;3);&nbsp;(5,&nbsp;3);&nbsp;(4,&nbsp;3);&nbsp;(3,&nbsp;3);&nbsp;(2,&nbsp;2);&nbsp;(1,&nbsp;1)]<br>
<br>
<br>
<span class="constructor">CCLinq</span>.(<br>
&nbsp;&nbsp;<span class="constructor">IO</span>.slurp_file&nbsp;<span class="string">"/tmp/foo"</span><br>
&nbsp;&nbsp;|&gt;&nbsp;<span class="constructor">IO</span>.lines<br>
&nbsp;&nbsp;|&gt;&nbsp;sort&nbsp;()<br>
&nbsp;&nbsp;|&gt;&nbsp;<span class="constructor">IO</span>.to_file_lines&nbsp;<span class="string">"/tmp/bar"</span><br>
);;<br>
-&nbsp;:&nbsp;&nbsp;<span class="keywordsign">`</span><span class="constructor">Ok</span>&nbsp;()<br>
</code></pre>
<p>
<b>DEPRECATED, use "OLinq" (standalone library) instead</b>
<p>
<b>status: deprecated</b><br>
<h1 id="1_LINQlikeoperationsoncollections">LINQ-like operations on collections</h1>
<p>
The purpose is to provide powerful combinators to express iteration,
transformation and combination of collections of items. This module depends
on several other modules, including <a href="CCList.html"><code class="code"><span class="constructor">CCList</span></code></a> and <code class="code"><span class="constructor">CCSequence</span></code>.
<p>
Functions and operations are assumed to be referentially transparent, i.e.
they should not rely on external side effects, they should not rely on
the order of execution.<br>
</div>
<hr width="100%">
<pre><span id="TYPEsequence"><span class="keyword">type</span> <code class="type">'a</code> sequence</span> = <code class="type">('a -> unit) -> unit</code> </pre>
<pre><span id="TYPEequal"><span class="keyword">type</span> <code class="type">'a</code> equal</span> = <code class="type">'a -> 'a -> bool</code> </pre>
<pre><span id="TYPEord"><span class="keyword">type</span> <code class="type">'a</code> ord</span> = <code class="type">'a -> 'a -> int</code> </pre>
<pre><span id="TYPEhash"><span class="keyword">type</span> <code class="type">'a</code> hash</span> = <code class="type">'a -> int</code> </pre>
<pre><span id="TYPEwith_err"><span class="keyword">type</span> <code class="type">'a</code> with_err</span> = <code class="type">[ `Error of string | `Ok of 'a ]</code> </pre>
<pre><span class="keyword">module</span> <a href="CCLinq.PMap.html">PMap</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.PMap.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info">
Polymorphic Maps
</div>
<br>
<h2 id="2_Queryoperators">Query operators</h2><br>
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> </pre>
<div class="info ">
Type of a query that returns zero, one or more values of type 'a<br>
</div>
<br>
<h6 id="6_Initialvalues">Initial values</h6><br>
<pre><span id="VALempty"><span class="keyword">val</span> empty</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Empty collection<br>
</div>
<pre><span id="VALstart"><span class="keyword">val</span> start</span> : <code class="type">'a -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<span class="warning">Deprecated.</span>since 0.13, use <a href="CCLinq.html#VALreturn"><code class="code"><span class="constructor">CCLinq</span>.return</code></a> instead<br>
Start with a single value<br>
</div>
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Return one value<br>
</div>
<pre><span id="VALof_list"><span class="keyword">val</span> of_list</span> : <code class="type">'a list -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Query that just returns the elements of the list<br>
</div>
<pre><span id="VALof_array"><span class="keyword">val</span> of_array</span> : <code class="type">'a array -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_array_i"><span class="keyword">val</span> of_array_i</span> : <code class="type">'a array -> (int * 'a) <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALrange"><span class="keyword">val</span> range</span> : <code class="type">int -> int -> int <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">range i j</code> goes from <code class="code">i</code> up to <code class="code">j</code> included<br>
</div>
<pre><span id="VAL(--)"><span class="keyword">val</span> (--)</span> : <code class="type">int -> int -> int <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Synonym to <a href="CCLinq.html#VALrange"><code class="code"><span class="constructor">CCLinq</span>.range</code></a><br>
</div>
<pre><span id="VALof_hashtbl"><span class="keyword">val</span> of_hashtbl</span> : <code class="type">('a, 'b) Hashtbl.t -> ('a * 'b) <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_seq"><span class="keyword">val</span> of_seq</span> : <code class="type">'a <a href="CCLinq.html#TYPEsequence">sequence</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Query that returns the elements of the given sequence.<br>
</div>
<pre><span id="VALof_queue"><span class="keyword">val</span> of_queue</span> : <code class="type">'a Queue.t -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_stack"><span class="keyword">val</span> of_stack</span> : <code class="type">'a Stack.t -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_string"><span class="keyword">val</span> of_string</span> : <code class="type">string -> char <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Traverse the characters of the string<br>
</div>
<br>
<h6 id="6_Execution">Execution</h6><br>
<pre><span id="VALrun"><span class="keyword">val</span> run</span> : <code class="type">?limit:int -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEsequence">sequence</a></code></pre><div class="info ">
Execute the query, possibly returning an error if things go wrong<br>
</div>
<div class="param_info"><code class="code">limit</code> : max number of values to return</div>
<pre><span id="VALrun1"><span class="keyword">val</span> run1</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a</code></pre><div class="info ">
Run the query and return the first value<br>
<b>Raises</b> <code>Not_found</code> if the query succeeds with 0 element<br>
</div>
<pre><span id="VALrun_no_optim"><span class="keyword">val</span> run_no_optim</span> : <code class="type">?limit:int -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEsequence">sequence</a></code></pre><div class="info ">
Run without any optimization<br>
</div>
<br>
<h6 id="6_Basics">Basics</h6><br>
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Map each value<br>
</div>
<pre><span id="VAL(>|=)"><span class="keyword">val</span> (&gt;|=)</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> ('a -> 'b) -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Infix synonym of <a href="CCLinq.html#VALmap"><code class="code"><span class="constructor">CCLinq</span>.map</code></a><br>
</div>
<pre><span id="VALfilter"><span class="keyword">val</span> filter</span> : <code class="type">('a -> bool) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Filter out values that do not satisfy predicate<br>
</div>
<pre><span id="VALsize"><span class="keyword">val</span> size</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> int <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">size t</code> returns one value, the number of items returned by <code class="code">t</code><br>
</div>
<pre><span id="VALchoose"><span class="keyword">val</span> choose</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Choose one element (if any, otherwise empty) in the collection.
This is like a "cut" in prolog.<br>
</div>
<pre><span id="VALfilter_map"><span class="keyword">val</span> filter_map</span> : <code class="type">('a -> 'b option) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Filter and map elements at once<br>
</div>
<pre><span id="VALflat_map"><span class="keyword">val</span> flat_map</span> : <code class="type">('a -> 'b <a href="CCLinq.html#TYPEsequence">sequence</a>) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Same as <a href="CCLinq.html#VALflat_map"><code class="code"><span class="constructor">CCLinq</span>.flat_map</code></a> but using sequences<br>
</div>
<pre><span id="VALflat_map_l"><span class="keyword">val</span> flat_map_l</span> : <code class="type">('a -> 'b list) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
map each element to a collection and flatten the result<br>
</div>
<pre><span id="VALflatten"><span class="keyword">val</span> flatten</span> : <code class="type">'a list <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALflatten_seq"><span class="keyword">val</span> flatten_seq</span> : <code class="type">'a <a href="CCLinq.html#TYPEsequence">sequence</a> <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALtake"><span class="keyword">val</span> take</span> : <code class="type">int -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Take at most <code class="code">n</code> elements<br>
</div>
<pre><span id="VALtake_while"><span class="keyword">val</span> take_while</span> : <code class="type">('a -> bool) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Take elements while they satisfy a predicate<br>
</div>
<pre><span id="VALsort"><span class="keyword">val</span> sort</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Sort items by the given comparison function<br>
</div>
<pre><span id="VALdistinct"><span class="keyword">val</span> distinct</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Remove duplicate elements from the input collection.
All elements in the result are distinct.<br>
</div>
<br>
<h6 id="6_Aggregation">Aggregation</h6><br>
<pre><span id="VALgroup_by"><span class="keyword">val</span> group_by</span> : <code class="type">?cmp:'b <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'b <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'b <a href="CCLinq.html#TYPEhash">hash</a> -><br> ('a -> 'b) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> ('b, 'a list) <a href="CCLinq.PMap.html#TYPEt">PMap.t</a> <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">group_by f</code> takes a collection <code class="code">c</code> as input, and returns
a multimap <code class="code">m</code> such that for each <code class="code">x</code> in <code class="code">c</code>,
<code class="code">x</code> occurs in <code class="code">m</code> under the key <code class="code">f x</code>. In other words, <code class="code">f</code> is used
to obtain a key from <code class="code">x</code>, and <code class="code">x</code> is added to the multimap using this key.<br>
</div>
<pre><span id="VALgroup_by'"><span class="keyword">val</span> group_by'</span> : <code class="type">?cmp:'b <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'b <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'b <a href="CCLinq.html#TYPEhash">hash</a> -> ('a -> 'b) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> ('b * 'a list) <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALcount"><span class="keyword">val</span> count</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'a <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'a <a href="CCLinq.html#TYPEhash">hash</a> -><br> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> ('a, int) <a href="CCLinq.PMap.html#TYPEt">PMap.t</a> <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">count c</code> returns a map from elements of <code class="code">c</code> to the number
of time those elements occur.<br>
</div>
<pre><span id="VALcount'"><span class="keyword">val</span> count'</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> ('a * int) <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALfold"><span class="keyword">val</span> fold</span> : <code class="type">('b -> 'a -> 'b) -> 'b -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Fold over the collection<br>
</div>
<pre><span id="VALreduce"><span class="keyword">val</span> reduce</span> : <code class="type">('a -> 'b) -> ('a -> 'b -> 'b) -> ('b -> 'c) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'c <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">reduce start mix stop q</code> uses <code class="code">start</code> on the first element of <code class="code">q</code>,
and combine the result with following elements using <code class="code">mix</code>. The final
value is transformed using <code class="code">stop</code>.<br>
</div>
<pre><span id="VALis_empty"><span class="keyword">val</span> is_empty</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> bool <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALsum"><span class="keyword">val</span> sum</span> : <code class="type">int <a href="CCLinq.html#TYPEt">t</a> -> int <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALcontains"><span class="keyword">val</span> contains</span> : <code class="type">?eq:'a <a href="CCLinq.html#TYPEequal">equal</a> -> 'a -> 'a <a href="CCLinq.html#TYPEt">t</a> -> bool <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALaverage"><span class="keyword">val</span> average</span> : <code class="type">int <a href="CCLinq.html#TYPEt">t</a> -> int <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALmax"><span class="keyword">val</span> max</span> : <code class="type">int <a href="CCLinq.html#TYPEt">t</a> -> int <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALmin"><span class="keyword">val</span> min</span> : <code class="type">int <a href="CCLinq.html#TYPEt">t</a> -> int <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALfor_all"><span class="keyword">val</span> for_all</span> : <code class="type">('a -> bool) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> bool <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALexists"><span class="keyword">val</span> exists</span> : <code class="type">('a -> bool) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> bool <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALfind"><span class="keyword">val</span> find</span> : <code class="type">('a -> bool) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a option <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALfind_map"><span class="keyword">val</span> find_map</span> : <code class="type">('a -> 'b option) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b option <a href="CCLinq.html#TYPEt">t</a></code></pre><br>
<h6 id="6_BinaryOperators">Binary Operators</h6><br>
<pre><span id="VALjoin"><span class="keyword">val</span> join</span> : <code class="type">?cmp:'key <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'key <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'key <a href="CCLinq.html#TYPEhash">hash</a> -><br> ('a -> 'key) -><br> ('b -> 'key) -><br> merge:('key -> 'a -> 'b -> 'c option) -><br> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a> -> 'c <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">join key1 key2 ~merge</code> is a binary operation
that takes two collections <code class="code">a</code> and <code class="code">b</code>, projects their
elements resp. with <code class="code">key1</code> and <code class="code">key2</code>, and combine
values <code class="code">(x,y)</code> from <code class="code">(a,b)</code> with the same <code class="code">key</code>
using <code class="code">merge</code>. If <code class="code">merge</code> returns <code class="code"><span class="constructor">None</span></code>, the combination
of values is discarded.<br>
</div>
<pre><span id="VALgroup_join"><span class="keyword">val</span> group_join</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'a <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'a <a href="CCLinq.html#TYPEhash">hash</a> -><br> ('b -> 'a) -><br> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a> -> ('a, 'b list) <a href="CCLinq.PMap.html#TYPEt">PMap.t</a> <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">group_join key2</code> associates to every element <code class="code">x</code> of
the first collection, all the elements <code class="code">y</code> of the second
collection such that <code class="code">eq x (key y)</code><br>
</div>
<pre><span id="VALproduct"><span class="keyword">val</span> product</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a> -> ('a * 'b) <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Cartesian product<br>
</div>
<pre><span id="VALappend"><span class="keyword">val</span> append</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Append two collections together<br>
</div>
<pre><span id="VALinter"><span class="keyword">val</span> inter</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'a <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'a <a href="CCLinq.html#TYPEhash">hash</a> -> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Intersection of two collections. Each element will occur at most once
in the result<br>
</div>
<pre><span id="VALunion"><span class="keyword">val</span> union</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'a <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'a <a href="CCLinq.html#TYPEhash">hash</a> -> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Union of two collections. Each element will occur at most once
in the result<br>
</div>
<pre><span id="VALdiff"><span class="keyword">val</span> diff</span> : <code class="type">?cmp:'a <a href="CCLinq.html#TYPEord">ord</a> -><br> ?eq:'a <a href="CCLinq.html#TYPEequal">equal</a> -><br> ?hash:'a <a href="CCLinq.html#TYPEhash">hash</a> -> unit -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Set difference<br>
</div>
<br>
<h6 id="6_TupleandOptions">Tuple and Options</h6><br>
<br>
<h6 id="6_TupleandOptions">Tuple and Options</h6><br>
<br>
Specialized projection operators<br>
<pre><span id="VALfst"><span class="keyword">val</span> fst</span> : <code class="type">('a * 'b) <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALsnd"><span class="keyword">val</span> snd</span> : <code class="type">('a * 'b) <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALmap1"><span class="keyword">val</span> map1</span> : <code class="type">('a -> 'b) -> ('a * 'c) <a href="CCLinq.html#TYPEt">t</a> -> ('b * 'c) <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALmap2"><span class="keyword">val</span> map2</span> : <code class="type">('a -> 'b) -> ('c * 'a) <a href="CCLinq.html#TYPEt">t</a> -> ('c * 'b) <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALflatten_opt"><span class="keyword">val</span> flatten_opt</span> : <code class="type">'a option <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Flatten the collection by removing options<br>
</div>
<br>
<h6 id="6_Applicative">Applicative</h6><br>
<pre><span id="VALpure"><span class="keyword">val</span> pure</span> : <code class="type">'a -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Synonym to <a href="CCLinq.html#VALreturn"><code class="code"><span class="constructor">CCLinq</span>.return</code></a><br>
</div>
<pre><span id="VALapp"><span class="keyword">val</span> app</span> : <code class="type">('a -> 'b) <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Apply each function to each value<br>
</div>
<pre><span id="VAL(<*>)"><span class="keyword">val</span> (&lt;*&gt;)</span> : <code class="type">('a -> 'b) <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Infix synonym to <a href="CCLinq.html#VALapp"><code class="code"><span class="constructor">CCLinq</span>.app</code></a><br>
</div>
<br>
<h6 id="6_Monad">Monad</h6>
<p>
Careful, those operators do not allow any optimization before running the
query, they might therefore be pretty slow.<br>
<pre><span id="VALbind"><span class="keyword">val</span> bind</span> : <code class="type">('a -> 'b <a href="CCLinq.html#TYPEt">t</a>) -> 'a <a href="CCLinq.html#TYPEt">t</a> -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Use the result of a query to build another query and immediately run it.<br>
</div>
<pre><span id="VAL(>>=)"><span class="keyword">val</span> (&gt;&gt;=)</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> ('a -> 'b <a href="CCLinq.html#TYPEt">t</a>) -> 'b <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Infix version of <a href="CCLinq.html#VALbind"><code class="code"><span class="constructor">CCLinq</span>.bind</code></a><br>
</div>
<br>
<h6 id="6_Misc">Misc</h6><br>
<pre><span id="VALlazy_"><span class="keyword">val</span> lazy_</span> : <code class="type">'a lazy_t <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALopt_unwrap"><span class="keyword">val</span> opt_unwrap</span> : <code class="type">'a option <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALreflect"><span class="keyword">val</span> reflect</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEsequence">sequence</a> <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">reflect q</code> evaluates all values in <code class="code">q</code> and returns a sequence
of all those values. Also blocks optimizations<br>
</div>
<br>
<h6 id="6_Infix">Infix</h6><br>
<pre><span class="keyword">module</span> <a href="CCLinq.Infix.html">Infix</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.Infix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><br>
<h6 id="6_Adapters">Adapters</h6><br>
<pre><span id="VALto_seq"><span class="keyword">val</span> to_seq</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a <a href="CCLinq.html#TYPEsequence">sequence</a> <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Build a (re-usable) sequence of elements, which can then be
converted into other structures<br>
</div>
<pre><span id="VALto_hashtbl"><span class="keyword">val</span> to_hashtbl</span> : <code class="type">('a * 'b) <a href="CCLinq.html#TYPEt">t</a> -> ('a, 'b) Hashtbl.t <a href="CCLinq.html#TYPEt">t</a></code></pre><div class="info ">
Build a hashtable from the collection<br>
</div>
<pre><span id="VALto_queue"><span class="keyword">val</span> to_queue</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a Queue.t <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span id="VALto_stack"><span class="keyword">val</span> to_stack</span> : <code class="type">'a <a href="CCLinq.html#TYPEt">t</a> -> 'a Stack.t <a href="CCLinq.html#TYPEt">t</a></code></pre>
<pre><span class="keyword">module</span> <a href="CCLinq.List.html">List</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.List.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span class="keyword">module</span> <a href="CCLinq.Array.html">Array</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.Array.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span class="keyword">module</span> <a href="CCLinq.AdaptSet.html">AdaptSet</a> <code class="code">(</code><code class="code"><span class="constructor">S</span></code><code class="code"> : </code><code class="type">Set.S</code><code class="code">) </code>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.AdaptSet.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span class="keyword">module</span> <a href="CCLinq.AdaptMap.html">AdaptMap</a> <code class="code">(</code><code class="code"><span class="constructor">M</span></code><code class="code"> : </code><code class="type">Map.S</code><code class="code">) </code>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.AdaptMap.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span class="keyword">module</span> <a href="CCLinq.IO.html">IO</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLinq.IO.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html>