239 lines
3.7 KiB
HTML
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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Stdlib.Seq - no description
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Stdlib.Seq
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Seq</B>
|
|
|
|
<BR> :
|
|
<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 -> '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> | Nil
|
|
<BR> | Cons
|
|
<B>of </B>
|
|
|
|
<B>'a * 'a t</B>
|
|
|
|
<I> </I>
|
|
|
|
<BR> (* A fully-evaluated list node, either empty or containing an element
|
|
and a delayed tail.
|
|
<BR> *)
|
|
<BR>
|
|
<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 -> 'a t</B>
|
|
|
|
<P>
|
|
The singleton sequence containing only the given element.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val map </I>
|
|
|
|
:
|
|
<B>('a -> 'b) -> 'a t -> '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 -> bool) -> 'a t -> '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 -> 'b option) -> 'a t -> '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 -> 'b t) -> 'a t -> '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 -> 'b -> 'a) -> 'a -> 'b t -> '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 -> unit) -> 'a t -> 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"> </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>
|