<!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=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Extlib.OptParse.html"> <link rel="next" href="Extlib.PMap.html"> <link rel="Up" href="Extlib.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 classes" rel=Appendix href="index_classes.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="BatArray" rel="Chapter" href="BatArray.html"> <link title="BatAvlTree" rel="Chapter" href="BatAvlTree.html"> <link title="BatBase64" rel="Chapter" href="BatBase64.html"> <link title="BatBig_int" rel="Chapter" href="BatBig_int.html"> <link title="BatBigarray" rel="Chapter" href="BatBigarray.html"> <link title="BatBitSet" rel="Chapter" href="BatBitSet.html"> <link title="BatBool" rel="Chapter" href="BatBool.html"> <link title="BatBounded" rel="Chapter" href="BatBounded.html"> <link title="BatBuffer" rel="Chapter" href="BatBuffer.html"> <link title="BatCache" rel="Chapter" href="BatCache.html"> <link title="BatChar" rel="Chapter" href="BatChar.html"> <link title="BatCharParser" rel="Chapter" href="BatCharParser.html"> <link title="BatComplex" rel="Chapter" href="BatComplex.html"> <link title="BatConcurrent" rel="Chapter" href="BatConcurrent.html"> <link title="BatDeque" rel="Chapter" href="BatDeque.html"> <link title="BatDigest" rel="Chapter" href="BatDigest.html"> <link title="BatDllist" rel="Chapter" href="BatDllist.html"> <link title="BatDynArray" rel="Chapter" href="BatDynArray.html"> <link title="BatEnum" rel="Chapter" href="BatEnum.html"> <link title="BatFile" rel="Chapter" href="BatFile.html"> <link title="BatFingerTree" rel="Chapter" href="BatFingerTree.html"> <link title="BatFloat" rel="Chapter" href="BatFloat.html"> <link title="BatFormat" rel="Chapter" href="BatFormat.html"> <link title="BatGc" rel="Chapter" href="BatGc.html"> <link title="BatGenlex" rel="Chapter" href="BatGenlex.html"> <link title="BatGlobal" rel="Chapter" href="BatGlobal.html"> <link title="BatHashcons" rel="Chapter" href="BatHashcons.html"> <link title="BatHashtbl" rel="Chapter" href="BatHashtbl.html"> <link title="BatHeap" rel="Chapter" href="BatHeap.html"> <link title="BatIMap" rel="Chapter" href="BatIMap.html"> <link title="BatIO" rel="Chapter" href="BatIO.html"> <link title="BatISet" rel="Chapter" href="BatISet.html"> <link title="BatInnerIO" rel="Chapter" href="BatInnerIO.html"> <link title="BatInnerPervasives" rel="Chapter" href="BatInnerPervasives.html"> <link title="BatInnerWeaktbl" rel="Chapter" href="BatInnerWeaktbl.html"> <link title="BatInt" rel="Chapter" href="BatInt.html"> <link title="BatInt32" rel="Chapter" href="BatInt32.html"> <link title="BatInt64" rel="Chapter" href="BatInt64.html"> <link title="BatInterfaces" rel="Chapter" href="BatInterfaces.html"> <link title="BatLazyList" rel="Chapter" href="BatLazyList.html"> <link title="BatLexing" rel="Chapter" href="BatLexing.html"> <link title="BatList" rel="Chapter" href="BatList.html"> <link title="BatLog" rel="Chapter" href="BatLog.html"> <link title="BatLogger" rel="Chapter" href="BatLogger.html"> <link title="BatMap" rel="Chapter" href="BatMap.html"> <link title="BatMarshal" rel="Chapter" href="BatMarshal.html"> <link title="BatMultiMap" rel="Chapter" href="BatMultiMap.html"> <link title="BatMultiPMap" rel="Chapter" href="BatMultiPMap.html"> <link title="BatMutex" rel="Chapter" href="BatMutex.html"> <link title="BatNativeint" rel="Chapter" href="BatNativeint.html"> <link title="BatNum" rel="Chapter" href="BatNum.html"> <link title="BatNumber" rel="Chapter" href="BatNumber.html"> <link title="BatOo" rel="Chapter" href="BatOo.html"> <link title="BatOptParse" rel="Chapter" href="BatOptParse.html"> <link title="BatOption" rel="Chapter" href="BatOption.html"> <link title="BatOrd" rel="Chapter" href="BatOrd.html"> <link title="BatParserCo" rel="Chapter" href="BatParserCo.html"> <link title="BatPathGen" rel="Chapter" href="BatPathGen.html"> <link title="BatPervasives" rel="Chapter" href="BatPervasives.html"> <link title="BatPrintexc" rel="Chapter" href="BatPrintexc.html"> <link title="BatPrintf" rel="Chapter" href="BatPrintf.html"> <link title="BatQueue" rel="Chapter" href="BatQueue.html"> <link title="BatRMutex" rel="Chapter" href="BatRMutex.html"> <link title="BatRandom" rel="Chapter" href="BatRandom.html"> <link title="BatRef" rel="Chapter" href="BatRef.html"> <link title="BatRefList" rel="Chapter" href="BatRefList.html"> <link title="BatResult" rel="Chapter" href="BatResult.html"> <link title="BatReturn" rel="Chapter" href="BatReturn.html"> <link title="BatScanf" rel="Chapter" href="BatScanf.html"> <link title="BatSeq" rel="Chapter" href="BatSeq.html"> <link title="BatSet" rel="Chapter" href="BatSet.html"> <link title="BatSplay" rel="Chapter" href="BatSplay.html"> <link title="BatStack" rel="Chapter" href="BatStack.html"> <link title="BatStream" rel="Chapter" href="BatStream.html"> <link title="BatString" rel="Chapter" href="BatString.html"> <link title="BatSubstring" rel="Chapter" href="BatSubstring.html"> <link title="BatSys" rel="Chapter" href="BatSys.html"> <link title="BatText" rel="Chapter" href="BatText.html"> <link title="BatTuple" rel="Chapter" href="BatTuple.html"> <link title="BatUChar" rel="Chapter" href="BatUChar.html"> <link title="BatUTF8" rel="Chapter" href="BatUTF8.html"> <link title="BatUnit" rel="Chapter" href="BatUnit.html"> <link title="BatUnix" rel="Chapter" href="BatUnix.html"> <link title="BatUref" rel="Chapter" href="BatUref.html"> <link title="BatVect" rel="Chapter" href="BatVect.html"> <link title="Batteries" rel="Chapter" href="Batteries.html"> <link title="BatteriesConfig" rel="Chapter" href="BatteriesConfig.html"> <link title="BatteriesPrint" rel="Chapter" href="BatteriesPrint.html"> <link title="BatteriesThread" rel="Chapter" href="BatteriesThread.html"> <link title="Extlib" rel="Chapter" href="Extlib.html"><link title="The Option Monad" rel="Section" href="#6_TheOptionMonad"> <link title="Boilerplate code" rel="Section" href="#6_Boilerplatecode"> <link title="Printing" rel="Subsection" href="#7_Printing"> <title>Batteries user guide : Extlib.Option</title> </head> <body> <div class="navbar"><a class="pre" href="Extlib.OptParse.html" title="Extlib.OptParse">Previous</a> <a class="up" href="Extlib.html" title="Extlib">Up</a> <a class="post" href="Extlib.PMap.html" title="Extlib.PMap">Next</a> </div> <h1>Module <a href="type_Extlib.Option.html">Extlib.Option</a></h1> <pre><span class="keyword">module</span> Option: <code class="type">BatOption</code></pre><hr width="100%"> <pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> = <code class="type">'a option</code> </pre> <pre><span id="VALmay"><span class="keyword">val</span> may</span> : <code class="type">('a -> unit) -> 'a option -> unit</code></pre><div class="info "> <code class="code">may f (<span class="constructor">Some</span> x)</code> calls <code class="code">f x</code> and <code class="code">may f <span class="constructor">None</span></code> does nothing.<br> </div> <pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'a option -> 'b option</code></pre><div class="info "> <code class="code">map f (<span class="constructor">Some</span> x)</code> returns <code class="code"><span class="constructor">Some</span> (f x)</code> and <code class="code">map f <span class="constructor">None</span></code> returns <code class="code"><span class="constructor">None</span></code>.<br> </div> <pre><span id="VALbind"><span class="keyword">val</span> bind</span> : <code class="type">'a option -> ('a -> 'b option) -> 'b option</code></pre><div class="info "> <code class="code">bind (<span class="constructor">Some</span> x) f</code> returns <code class="code">f x</code> and <code class="code">bind <span class="constructor">None</span> f</code> returns <code class="code"><span class="constructor">None</span></code>.<br> </div> <pre><span id="VALapply"><span class="keyword">val</span> apply</span> : <code class="type">('a -> 'a) option -> 'a -> 'a</code></pre><div class="info "> <code class="code">apply <span class="constructor">None</span> x</code> returns <code class="code">x</code> and <code class="code">apply (<span class="constructor">Some</span> f) x</code> returns <code class="code">f x</code><br> </div> <pre><span id="VALfilter"><span class="keyword">val</span> filter</span> : <code class="type">('a -> bool) -> 'a option -> 'a option</code></pre><div class="info "> <code class="code">filter f <span class="constructor">None</span></code> returns <code class="code"><span class="constructor">None</span></code>, <code class="code">filter f (<span class="constructor">Some</span> x)</code> returns <code class="code"><span class="constructor">Some</span> x</code> if <code class="code">f x</code> is true, and <code class="code"><span class="constructor">None</span></code> otherwise.<br> </div> <pre><span id="VALdefault"><span class="keyword">val</span> default</span> : <code class="type">'a -> 'a option -> 'a</code></pre><div class="info "> <code class="code">default x (<span class="constructor">Some</span> v)</code> returns <code class="code">v</code> and <code class="code">default x <span class="constructor">None</span></code> returns <code class="code">x</code>.<br> </div> <pre><span id="VAL(|?)"><span class="keyword">val</span> (|?)</span> : <code class="type">'a option -> 'a -> 'a</code></pre><div class="info "> Like <a href="BatOption.html#VALdefault"><code class="code"><span class="constructor">BatOption</span>.default</code></a>, with the arguments reversed. <code class="code"><span class="constructor">None</span> |? 10</code> returns <code class="code">10</code>, while <code class="code"><span class="constructor">Some</span> <span class="string">"foo"</span> |? <span class="string">"bar"</span></code> returns <code class="code"><span class="string">"foo"</span></code>. <p> <b>Note</b> This operator does not short circuit like <code class="code">( <span class="keywordsign">||</span> )</code> and <code class="code">( <span class="keywordsign">&&</span> )</code>. Both arguments will be evaluated.<br> <b>Since</b> 2.0<br> </div> <pre><span id="VALdefault_delayed"><span class="keyword">val</span> default_delayed</span> : <code class="type">(unit -> 'a) -> 'a option -> 'a</code></pre><div class="info "> Like <a href="BatOption.html#VALdefault"><code class="code"><span class="constructor">BatOption</span>.default</code></a>, but the default value is passed as a thunk that is only computed if needed.<br> <b>Since</b> 2.1<br> </div> <pre><span id="VALmap_default"><span class="keyword">val</span> map_default</span> : <code class="type">('a -> 'b) -> 'b -> 'a option -> 'b</code></pre><div class="info "> <code class="code">map_default f x (<span class="constructor">Some</span> v)</code> returns <code class="code">f v</code> and <code class="code">map_default f x <span class="constructor">None</span></code> returns <code class="code">x</code>.<br> </div> <pre><span id="VALmap_default_delayed"><span class="keyword">val</span> map_default_delayed</span> : <code class="type">('a -> 'b) -> (unit -> 'b) -> 'a option -> 'b</code></pre><div class="info "> Like <a href="BatOption.html#VALmap_default"><code class="code"><span class="constructor">BatOption</span>.map_default</code></a>, but the default value is passed as a thunk that is only computed if needed.<br> <b>Since</b> 2.1<br> </div> <pre><span id="VALis_none"><span class="keyword">val</span> is_none</span> : <code class="type">'a option -> bool</code></pre><div class="info "> <code class="code">is_none <span class="constructor">None</span></code> returns <code class="code"><span class="keyword">true</span></code> otherwise it returns <code class="code"><span class="keyword">false</span></code>.<br> </div> <pre><span id="VALis_some"><span class="keyword">val</span> is_some</span> : <code class="type">'a option -> bool</code></pre><div class="info "> <code class="code">is_some (<span class="constructor">Some</span> x)</code> returns <code class="code"><span class="keyword">true</span></code> otherwise it returns <code class="code"><span class="keyword">false</span></code>.<br> </div> <pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type">'a option -> 'a</code></pre><div class="info "> <code class="code">get (<span class="constructor">Some</span> x)</code> returns <code class="code">x</code>.<br> <b>Raises</b> <code>Invalid_argument</code> on <code class="code">get <span class="constructor">None</span></code>.<br> </div> <pre><span id="VALget_exn"><span class="keyword">val</span> get_exn</span> : <code class="type">'a option -> exn -> 'a</code></pre><div class="info "> <code class="code">get_exn (<span class="constructor">Some</span> x) e</code> returns <code class="code">x</code> and <code class="code">get_exn <span class="constructor">None</span> e</code> raises <code class="code">e</code>.<br> </div> <pre><span id="VALcompare"><span class="keyword">val</span> compare</span> : <code class="type">?cmp:('a -> 'a -> int) -> 'a option -> 'a option -> int</code></pre><div class="info "> Compare two options, possibly using custom comparators for the value. <code class="code"><span class="constructor">None</span></code> is always assumed to be less than <code class="code"><span class="constructor">Some</span> _</code>. The parameter <code class="code">cmp</code> defaults to <code class="code"><span class="constructor">Pervasives</span>.compare</code>.<br> </div> <pre><span id="VALeq"><span class="keyword">val</span> eq</span> : <code class="type">?eq:('a -> 'a -> bool) -> 'a option -> 'a option -> bool</code></pre><div class="info "> Test for equality between option types, possibly using a custom equality predicate. The parameter <code class="code">eq</code> defaults to <code class="code"><span class="constructor">Pervasives</span>.(=)</code>.<br> <b>Since</b> 1.4.0<br> </div> <pre><span id="VALenum"><span class="keyword">val</span> enum</span> : <code class="type">'a option -> 'a <a href="BatEnum.html#TYPEt">BatEnum.t</a></code></pre><div class="info "> <code class="code">enum (<span class="constructor">Some</span> x)</code> returns the singleton <code class="code">x</code>, while <code class="code">enum <span class="constructor">None</span></code> returns the empty enumeration.<br> </div> <pre><span id="VALof_enum"><span class="keyword">val</span> of_enum</span> : <code class="type">'a <a href="BatEnum.html#TYPEt">BatEnum.t</a> -> 'a option</code></pre><div class="info "> <code class="code">of_enum e</code> consumes the first element of <code class="code">e</code>, if it exists, and returns <code class="code"><span class="constructor">Some</span> e</code>. If <code class="code">e</code> is empty, return <code class="code"><span class="constructor">None</span></code>.<br> </div> <br> <h6 id="6_TheOptionMonad">The Option Monad</h6><br> <pre><span class="keyword">module</span> <a href="BatOption.Monad.html">Monad</a>: <code class="code"><span class="keyword">sig</span></code> <a href="BatOption.Monad.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info"> This module provides everything needed to write and execute computations in the Option monad. </div> <br> <h6 id="6_Boilerplatecode">Boilerplate code</h6><br> <br> <div class="h7" id="7_Printing">Printing</div><br> <pre><span id="VALprint"><span class="keyword">val</span> print</span> : <code class="type">('a <a href="BatInnerIO.html#TYPEoutput">BatInnerIO.output</a> -> 'b -> unit) -><br> 'a <a href="BatInnerIO.html#TYPEoutput">BatInnerIO.output</a> -> 'b <a href="BatOption.html#TYPEt">t</a> -> unit</code></pre> <pre><span class="keyword">module</span> <a href="BatOption.Labels.html">Labels</a>: <code class="code"><span class="keyword">sig</span></code> <a href="BatOption.Labels.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info"> Operations on options, with labels. </div> <pre><span class="keyword">module</span> <a href="BatOption.Infix.html">Infix</a>: <code class="code"><span class="keyword">sig</span></code> <a href="BatOption.Infix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html>