man-pages/man3/Option.3o.html
2021-03-31 01:06:50 +01:00

533 lines
4.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Option</TITLE>
</HEAD><BODY>
<H1>Option</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Option - Option values.
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Option
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Option</B>
<BR>&nbsp;:&nbsp;
<B>sig end</B>
<P>
<P>
Option values.
<P>
Option values explicitly indicate the presence or absence of a value.
<P>
<P>
<B>Since</B>
4.08
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<A NAME="lbAE">&nbsp;</A>
<H3>Options</H3>
<P>
<P>
<I>type </I>
<B>'a</B>
<I>t </I>
=
<B>'a option</B>
=
<BR>&nbsp;|&nbsp;None
<BR>&nbsp;|&nbsp;Some
<B>of </B>
<B>'a</B>
<BR>&nbsp;
<P>
The type for option values. Either
<B>None</B>
or a value
<B>Some v</B>
.
<P>
<P>
<P>
<I>val none </I>
:
<B>'a option</B>
<P>
<P>
<B>none</B>
is
<B>None</B>
.
<P>
<P>
<P>
<I>val some </I>
:
<B>'a -&gt; 'a option</B>
<P>
<P>
<B>some v</B>
is
<B>Some v</B>
.
<P>
<P>
<P>
<I>val value </I>
:
<B>'a option -&gt; default:'a -&gt; 'a</B>
<P>
<P>
<B>value o ~default</B>
is
<B>v</B>
if
<B>o</B>
is
<B>Some v</B>
and
<B>default</B>
otherwise.
<P>
<P>
<P>
<I>val get </I>
:
<B>'a option -&gt; 'a</B>
<P>
<P>
<B>get o</B>
is
<B>v</B>
if
<B>o</B>
is
<B>Some v</B>
and
<P>
<P>
<B>Raises Invalid_argument</B>
otherwise.
<P>
<P>
<P>
<I>val bind </I>
:
<B>'a option -&gt; ('a -&gt; 'b option) -&gt; 'b option</B>
<P>
<P>
<B>bind o f</B>
is
<B>f v</B>
if
<B>o</B>
is
<B>Some v</B>
and
<B>None</B>
if
<B>o</B>
is
<B>None</B>
.
<P>
<P>
<P>
<I>val join </I>
:
<B>'a option option -&gt; 'a option</B>
<P>
<P>
<B>join oo</B>
is
<B>Some v</B>
if
<B>oo</B>
is
<B>Some (Some v)</B>
and
<B>None</B>
otherwise.
<P>
<P>
<P>
<I>val map </I>
:
<B>('a -&gt; 'b) -&gt; 'a option -&gt; 'b option</B>
<P>
<P>
<B>map f o</B>
is
<B>None</B>
if
<B>o</B>
is
<B>None</B>
and
<B>Some (f v)</B>
is
<B>o</B>
is
<B>Some v</B>
.
<P>
<P>
<P>
<I>val fold </I>
:
<B>none:'a -&gt; some:('b -&gt; 'a) -&gt; 'b option -&gt; 'a</B>
<P>
<P>
<B>fold ~none ~some o</B>
is
<B>none</B>
if
<B>o</B>
is
<B>None</B>
and
<B>some v</B>
if
<B>o</B>
is
<B>Some v</B>
.
<P>
<P>
<P>
<I>val iter </I>
:
<B>('a -&gt; unit) -&gt; 'a option -&gt; unit</B>
<P>
<P>
<B>iter f o</B>
is
<B>f v</B>
if
<B>o</B>
is
<B>Some v</B>
and
<B>()</B>
otherwise.
<P>
<P>
<P>
<P>
<A NAME="lbAF">&nbsp;</A>
<H3>Predicates and comparisons</H3>
<P>
<P>
<P>
<I>val is_none </I>
:
<B>'a option -&gt; bool</B>
<P>
<P>
<B>is_none o</B>
is
<B>true</B>
iff
<B>o</B>
is
<B>None</B>
.
<P>
<P>
<P>
<I>val is_some </I>
:
<B>'a option -&gt; bool</B>
<P>
<P>
<B>is_some o</B>
is
<B>true</B>
iff
<B>o</B>
is
<B>Some o</B>
.
<P>
<P>
<P>
<I>val equal </I>
:
<B>('a -&gt; 'a -&gt; bool) -&gt; 'a option -&gt; 'a option -&gt; bool</B>
<P>
<P>
<B>equal eq o0 o1</B>
is
<B>true</B>
iff
<B>o0</B>
and
<B>o1</B>
are both
<B>None</B>
or if
they are
<B>Some v0</B>
and
<B>Some v1</B>
and
<B>eq v0 v1</B>
is
<B>true</B>
.
<P>
<P>
<P>
<I>val compare </I>
:
<B>('a -&gt; 'a -&gt; int) -&gt; 'a option -&gt; 'a option -&gt; int</B>
<P>
<P>
<B>compare cmp o0 o1</B>
is a total order on options using
<B>cmp</B>
to compare
values wrapped by
<B>Some _</B>
.
<B>None</B>
is smaller than
<B>Some _</B>
values.
<P>
<P>
<P>
<P>
<A NAME="lbAG">&nbsp;</A>
<H3>Converting</H3>
<P>
<P>
<P>
<I>val to_result </I>
:
<B>none:'e -&gt; 'a option -&gt; ('a, 'e) result</B>
<P>
<P>
<B>to_result ~none o</B>
is
<B>Ok v</B>
if
<B>o</B>
is
<B>Some v</B>
and
<B>Error none</B>
otherwise.
<P>
<P>
<P>
<I>val to_list </I>
:
<B>'a option -&gt; 'a list</B>
<P>
<P>
<B>to_list o</B>
is
<B>[]</B>
if
<B>o</B>
is
<B>None</B>
and
<B>[v]</B>
if
<B>o</B>
is
<B>Some v</B>
.
<P>
<P>
<P>
<I>val to_seq </I>
:
<B>'a option -&gt; 'a Seq.t</B>
<P>
<P>
<B>to_seq o</B>
is
<B>o</B>
as a sequence.
<B>None</B>
is the empty sequence and
<B>Some v</B>
is the singleton sequence containing
<B>v</B>
.
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
<DL>
<DT id="4"><A HREF="#lbAE">Options</A><DD>
<DT id="5"><A HREF="#lbAF">Predicates and comparisons</A><DD>
<DT id="6"><A HREF="#lbAG">Converting</A><DD>
</DL>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:49 GMT, March 31, 2021
</BODY>
</HTML>