linol/lwt/Lwt/Infix/index.html
2025-04-03 13:23:17 +00:00

14 lines
7.7 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>Infix (lwt.Lwt.Infix)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.0"/><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">Index</a> &#x00BB; <a href="../../index.html">lwt</a> &#x00BB; <a href="../index.html">Lwt</a> &#x00BB; Infix</nav><header class="odoc-preamble"><h1>Module <code><span>Lwt.Infix</span></code></h1><p>This module provides several infix operators for making programming with Lwt more convenient.</p><p>To use it, open <code>Lwt.Infix</code>.</p><p>Of the operators declared in this module, only <code>&gt;|=</code> is recommended for new code. The only other commonly-used operator is <code>&gt;&gt;=</code>.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec value anchored" id="val-(&gt;&gt;=)"><a href="#val-(&gt;&gt;=)" class="anchor"></a><code><span><span class="keyword">val</span> (&gt;&gt;=) : <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../index.html#type-t">t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../index.html#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>p &gt;&gt;= f</code> is the same as <a href="../index.html#val-bind"><code>Lwt.bind</code></a><code> p f</code>. It requires <code>Lwt.Infix</code> to be opened in scope:</p><pre class="language-ocaml"><code>open Lwt.Infix
let () =
Lwt_main.run
(Lwt_io.(read_line stdin) &gt;&gt;= Lwt_io.printl)
(* ocamlfind opt -linkpkg -thread -package lwt.unix code.ml &amp;&amp; ./a.out *)</code></pre><p>It is recommended to use the PPX <code>let%lwt</code> syntax instead. This operator is the next-best choice. It is frequently found while reading existing Lwt code.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-(&gt;|=)"><a href="#val-(&gt;|=)" class="anchor"></a><code><span><span class="keyword">val</span> (&gt;|=) : <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../index.html#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>p &gt;|= f</code> is the same as <a href="../index.html#val-map"><code>Lwt.map</code></a><code> f p</code>. It requires <code>Lwt.Infix</code> to be opened in scope.</p><pre class="language-ocaml"><code>open Lwt.Infix
let () =
Lwt_main.run
(Lwt_io.(read_line stdin) &gt;|= ignore)
(* ocamlfind opt -linkpkg -thread -package lwt.unix code.ml &amp;&amp; ./a.out *)</code></pre></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-(&lt;&amp;&gt;)"><a href="#val-(&lt;&amp;&gt;)" class="anchor"></a><code><span><span class="keyword">val</span> (&lt;&amp;&gt;) : <span><span>unit <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>unit <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../index.html#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>p1 &lt;&amp;&gt; p2</code> is the same as <a href="../index.html#val-join"><code>Lwt.join</code></a><code> [p1; p2]</code>. It requires <code>Lwt.Infix</code> to be opened in scope.</p><p>Unlike with <a href="../index.html#val-bind"><code>Lwt.bind</code></a> and <a href="../index.html#val-map"><code>Lwt.map</code></a>, there are no problems with explicit <a href="../index.html#val-join"><code>Lwt.join</code></a> syntax, so using this operator is not recommended.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-(&lt;?&gt;)"><a href="#val-(&lt;?&gt;)" class="anchor"></a><code><span><span class="keyword">val</span> (&lt;?&gt;) : <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>p1 &lt;?&gt; p2</code> is the same as <a href="../index.html#val-choose"><code>Lwt.choose</code></a><code> [p1; p2]</code>. It requires <code>Lwt.Infix</code> to be opened in scope.</p><p>Unlike with <a href="../index.html#val-bind"><code>Lwt.bind</code></a> and <a href="../index.html#val-map"><code>Lwt.map</code></a>, there are no problems with explicit <a href="../index.html#val-choose"><code>Lwt.choose</code></a> syntax, so using this operator is not recommended.</p><p>Furthermore, most users actually need <a href="../index.html#val-pick"><code>Lwt.pick</code></a> instead of <a href="../index.html#val-choose"><code>Lwt.choose</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-(=&lt;&lt;)"><a href="#val-(=&lt;&lt;)" class="anchor"></a><code><span><span class="keyword">val</span> (=&lt;&lt;) : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../index.html#type-t">t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../index.html#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>f =&lt;&lt; p</code> is the same as <a href="../index.html#val-bind"><code>Lwt.bind</code></a><code> p f</code>. It requires <code>Lwt.Infix</code> to be opened in scope.</p><p>This operator is obscure and its use is discouraged. It is the same as <code>p &gt;&gt;= f</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-(=|&lt;)"><a href="#val-(=|&lt;)" class="anchor"></a><code><span><span class="keyword">val</span> (=|&lt;) : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../index.html#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>f =|&lt; p</code> is the same as <a href="../index.html#val-map"><code>Lwt.map</code></a><code> f p</code>. It requires <code>Lwt.Infix</code> to be opened in scope.</p><p>This operator is obscure and its use is discouraged. It is the same as <code>p &gt;|= f</code>.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Let_syntax"><a href="#module-Let_syntax" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Let_syntax/index.html">Let_syntax</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>This module provides support for <a href="https://github.com/janestreet/ppx_let">ppx_let</a>.</p></div></div></div></body></html>