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

239 lines
3.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Stdlib.Seq</TITLE>
</HEAD><BODY>
<H1>Stdlib.Seq</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>
Stdlib.Seq - no description
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Stdlib.Seq
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Seq</B>
<BR>&nbsp;:&nbsp;
<B>(module Stdlib__seq)</B>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
The type
<B>'a t</B>
is a delayed list, i.e. a list where some evaluation
is needed to access the next element. This makes it possible to build
infinite sequences, to build sequences as we traverse them, and to transform
them in a lazy fashion rather than upfront.
<P>
<I>type </I>
<B>'a</B>
<I>t </I>
=
<B>unit -&gt; 'a node</B>
<P>
<P>
The type of delayed lists containing elements of type
<B>'a</B>
.
Note that the concrete list node
<B>'a node</B>
is delayed under a closure,
not a
<B>lazy</B>
block, which means it might be recomputed every time
we access it.
<P>
<P>
<I>type </I>
<B>'a</B>
<I>node </I>
=
<BR>&nbsp;|&nbsp;Nil
<BR>&nbsp;|&nbsp;Cons
<B>of </B>
<B>'a * 'a t</B>
<I> </I>
<BR>&nbsp;&nbsp;(*&nbsp;A&nbsp;fully-evaluated&nbsp;list&nbsp;node,&nbsp;either&nbsp;empty&nbsp;or&nbsp;containing&nbsp;an&nbsp;element
and a delayed tail.
<BR>&nbsp;*)
<BR>&nbsp;
<P>
<P>
<P>
<P>
<I>val empty </I>
:
<B>'a t</B>
<P>
The empty sequence, containing no elements.
<P>
<P>
<P>
<I>val return </I>
:
<B>'a -&gt; 'a t</B>
<P>
The singleton sequence containing only the given element.
<P>
<P>
<P>
<I>val map </I>
:
<B>('a -&gt; 'b) -&gt; 'a t -&gt; 'b t</B>
<P>
<P>
<B>map f seq</B>
returns a new sequence whose elements are the elements of
<B>seq</B>
, transformed by
<B>f</B>
.
This transformation is lazy, it only applies when the result is traversed.
<P>
If
<B>seq = [1;2;3]</B>
, then
<B>map f seq = [f 1; f 2; f 3]</B>
.
<P>
<P>
<P>
<I>val filter </I>
:
<B>('a -&gt; bool) -&gt; 'a t -&gt; 'a t</B>
<P>
Remove from the sequence the elements that do not satisfy the
given predicate.
This transformation is lazy, it only applies when the result is
traversed.
<P>
<P>
<P>
<I>val filter_map </I>
:
<B>('a -&gt; 'b option) -&gt; 'a t -&gt; 'b t</B>
<P>
Apply the function to every element; if
<B>f x = None</B>
then
<B>x</B>
is dropped;
if
<B>f x = Some y</B>
then
<B>y</B>
is returned.
This transformation is lazy, it only applies when the result is
traversed.
<P>
<P>
<P>
<I>val flat_map </I>
:
<B>('a -&gt; 'b t) -&gt; 'a t -&gt; 'b t</B>
<P>
Map each element to a subsequence, then return each element of this
sub-sequence in turn.
This transformation is lazy, it only applies when the result is
traversed.
<P>
<P>
<P>
<I>val fold_left </I>
:
<B>('a -&gt; 'b -&gt; 'a) -&gt; 'a -&gt; 'b t -&gt; 'a</B>
<P>
Traverse the sequence from left to right, combining each element with the
accumulator using the given function.
The traversal happens immediately and will not terminate on infinite
sequences.
<P>
Also see
<B>List.fold_left</B>
<P>
<P>
<P>
<P>
<I>val iter </I>
:
<B>('a -&gt; unit) -&gt; 'a t -&gt; unit</B>
<P>
Iterate on the sequence, calling the (imperative) function on every element.
The traversal happens immediately and will not terminate on infinite
sequences.
<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>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:57 GMT, March 31, 2021
</BODY>
</HTML>