moonpool/dev/ocaml/Stdlib/Stream/index.html
2023-08-28 17:11:38 +00:00

2 lines
No EOL
9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Stream (ocaml.Stdlib.Stream)</title><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">ocaml</a> &#x00BB; <a href="../index.html">Stdlib</a> &#x00BB; Stream</nav><header class="odoc-preamble"><h1>Module <code><span>Stdlib.Stream</span></code></h1><ul class="at-tags"><li class="deprecated"><span class="at-tag">deprecated</span> Use the camlp-streams library instead.</li></ul><p>Streams and parsers.</p></header><nav class="odoc-toc"><ul><li><a href="#stream-builders">Stream builders</a></li><li><a href="#stream-iterator">Stream iterator</a></li><li><a href="#predefined-parsers">Predefined parsers</a></li><li><a href="#useful-functions">Useful functions</a></li></ul></nav><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> <span>!'a t</span></span></code></div><div class="spec-doc"><p>The type of streams holding values of type <code>'a</code>.</p></div></div><div class="odoc-spec"><div class="spec exception anchored" id="exception-Failure"><a href="#exception-Failure" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Failure</span></span></code></div><div class="spec-doc"><p>Raised by parsers when none of the first components of the stream patterns is accepted.</p></div></div><div class="odoc-spec"><div class="spec exception anchored" id="exception-Error"><a href="#exception-Error" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Error</span> <span class="keyword">of</span> string</span></code></div><div class="spec-doc"><p>Raised by parsers when the first component of a stream pattern is accepted, but one of the following components is rejected.</p></div></div><h2 id="stream-builders"><a href="#stream-builders" class="anchor"></a>Stream builders</h2><div class="odoc-spec"><div class="spec value anchored" id="val-from"><a href="#val-from" class="anchor"></a><code><span><span class="keyword">val</span> from : <span><span>(<span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>Stream.from f</code> returns a stream built from the function <code>f</code>. To create a new stream element, the function <code>f</code> is called with the current stream count. The user function <code>f</code> must return either <code>Some &lt;value&gt;</code> for a value or <code>None</code> to specify the end of the stream.</p><p>Do note that the indices passed to <code>f</code> may not start at <code>0</code> in the general case. For example, <code>[&lt; '0; '1; Stream.from f &gt;]</code> would call <code>f</code> the first time with count <code>2</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_list"><a href="#val-of_list" class="anchor"></a><code><span><span class="keyword">val</span> of_list : <span><span><span class="type-var">'a</span> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Return the stream holding the elements of the list in the same order.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_string"><a href="#val-of_string" class="anchor"></a><code><span><span class="keyword">val</span> of_string : <span>string <span class="arrow">&#45;&gt;</span></span> <span>char <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Return the stream of the characters of the string parameter.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_bytes"><a href="#val-of_bytes" class="anchor"></a><code><span><span class="keyword">val</span> of_bytes : <span>bytes <span class="arrow">&#45;&gt;</span></span> <span>char <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Return the stream of the characters of the bytes parameter.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_channel"><a href="#val-of_channel" class="anchor"></a><code><span><span class="keyword">val</span> of_channel : <span><a href="../index.html#type-in_channel">in_channel</a> <span class="arrow">&#45;&gt;</span></span> <span>char <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Return the stream of the characters read from the input channel.</p></div></div><h2 id="stream-iterator"><a href="#stream-iterator" class="anchor"></a>Stream iterator</h2><div class="odoc-spec"><div class="spec value anchored" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span><span class="keyword">val</span> iter : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>Stream.iter f s</code> scans the whole stream s, applying function <code>f</code> in turn to each stream element encountered.</p></div></div><h2 id="predefined-parsers"><a href="#predefined-parsers" class="anchor"></a>Predefined parsers</h2><div class="odoc-spec"><div class="spec value anchored" id="val-next"><a href="#val-next" class="anchor"></a><code><span><span class="keyword">val</span> next : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Return the first element of the stream and remove it from the stream.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Stream.Failure</span> <p>if the stream is empty.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span><span class="keyword">val</span> empty : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Return <code>()</code> if the stream is empty, else raise <a href="#exception-Failure"><code>Stream.Failure</code></a>.</p></div></div><h2 id="useful-functions"><a href="#useful-functions" class="anchor"></a>Useful functions</h2><div class="odoc-spec"><div class="spec value anchored" id="val-peek"><a href="#val-peek" class="anchor"></a><code><span><span class="keyword">val</span> peek : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span></span></code></div><div class="spec-doc"><p>Return <code>Some</code> of &quot;the first element&quot; of the stream, or <code>None</code> if the stream is empty.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-junk"><a href="#val-junk" class="anchor"></a><code><span><span class="keyword">val</span> junk : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Remove the first element of the stream, possibly unfreezing it before.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-count"><a href="#val-count" class="anchor"></a><code><span><span class="keyword">val</span> count : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Return the current count of the stream elements, i.e. the number of the stream elements discarded.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-npeek"><a href="#val-npeek" class="anchor"></a><code><span><span class="keyword">val</span> npeek : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> list</span></span></code></div><div class="spec-doc"><p><code>npeek n</code> returns the list of the <code>n</code> first elements of the stream, or all its remaining elements if less than <code>n</code> elements are available.</p></div></div></div></body></html>