mirror of
https://github.com/c-cube/nanoev.git
synced 2025-12-07 11:45:45 -05:00
2 lines
7.7 KiB
HTML
2 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Maybe (picos.Picos.Fiber.Maybe)</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> » <a href="../../../index.html">picos</a> » <a href="../../index.html">Picos</a> » <a href="../index.html">Fiber</a> » Maybe</nav><header class="odoc-preamble"><h1>Module <code><span>Fiber.Maybe</span></code></h1><p>An unboxed optional <a href="../index.html#type-t" title="Fiber.t">fiber</a>.</p></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#design-rationale">Design rationale</a></li></ul></nav></div><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> t</span></code></div><div class="spec-doc"><p>Either a <a href="../index.html#type-t" title="Fiber.t">fiber</a> or <a href="#val-nothing"><code>nothing</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-nothing"><a href="#val-nothing" class="anchor"></a><code><span><span class="keyword">val</span> nothing : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Not a fiber.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_fiber"><a href="#val-of_fiber" class="anchor"></a><code><span><span class="keyword">val</span> of_fiber : <span><a href="../index.html#type-fiber">fiber</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>of_fiber fiber</code> casts the fiber into an optional fiber.</p><p>🏎️ This performs no allocations.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_fiber"><a href="#val-to_fiber" class="anchor"></a><code><span><span class="keyword">val</span> to_fiber : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="../index.html#type-fiber">fiber</a></span></code></div><div class="spec-doc"><p><code>to_fiber</code> casts the optional fiber to a fiber.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>in case the optional fiber is <a href="#val-nothing"><code>nothing</code></a>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-current_if"><a href="#val-current_if" class="anchor"></a><code><span><span class="keyword">val</span> current_if : <span><span>bool option</span> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>current_if checked</code> returns <a href="#val-nothing"><code>nothing</code></a> in case <code>checked</code> is <code>Some false</code> and otherwise <code>of_fiber (Fiber.current ())</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-current_and_check_if"><a href="#val-current_and_check_if" class="anchor"></a><code><span><span class="keyword">val</span> current_and_check_if : <span><span>bool option</span> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>current_check_if checked</code> returns <a href="#val-nothing"><code>nothing</code></a> in case <code>checked</code> is <code>Some false</code> and otherwise <code>of_fiber (Fiber.current ())</code> and also calls <a href="../index.html#val-check"><code>Fiber.check</code></a> on the fiber.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-or_current"><a href="#val-or_current" class="anchor"></a><code><span><span class="keyword">val</span> or_current : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>or_current maybe</code> returns <code>of_fiber (Fiber.current ())</code> in case <code>maybe</code> is <a href="#val-nothing"><code>nothing</code></a> and otherwise returns <code>maybe</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_fiber_or_current"><a href="#val-to_fiber_or_current" class="anchor"></a><code><span><span class="keyword">val</span> to_fiber_or_current : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="../index.html#type-fiber">fiber</a></span></code></div><div class="spec-doc"><p><code>to_fiber_or_current maybe</code> returns <code>Fiber.current ()</code> in case <code>maybe</code> is <a href="#val-nothing"><code>nothing</code></a> and otherwise returns the fiber that <code>maybe</code> was cast from.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check"><a href="#val-check" class="anchor"></a><code><span><span class="keyword">val</span> check : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>check maybe</code> returns immediately if <code>maybe</code> is <code>nothing</code> and otherwise calls <a href="../index.html#val-check"><code>Fiber.check</code></a> on the fiber.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-equal"><a href="#val-equal" class="anchor"></a><code><span><span class="keyword">val</span> equal : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>equal l r</code> determines whether <code>l</code> and <code>r</code> are maybe equal. Specifically, if either <code>l</code> or <code>r</code> or both is <a href="#val-nothing"><code>nothing</code></a>, then they are considered (maybe) equal. Otherwise <code>l</code> and <code>r</code> are compared for <a href="../index.html#val-equal" title="Fiber.equal">physical equality</a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-unequal"><a href="#val-unequal" class="anchor"></a><code><span><span class="keyword">val</span> unequal : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>equal l r</code> determines whether <code>l</code> and <code>r</code> are maybe unequal. Specifically, if either <code>l</code> or <code>r</code> or both is <a href="#val-nothing"><code>nothing</code></a>, then they are considered (maybe) unequal. Otherwise <code>l</code> and <code>r</code> are compared for <a href="../index.html#val-equal" title="Fiber.equal">physical equality</a>.</p></div></div><h3 id="design-rationale"><a href="#design-rationale" class="anchor"></a>Design rationale</h3><p>The fiber identity is often needed only for the purpose of dynamically checking against programming errors. Unfortunately it can be relative expensive to obtain the <a href="../index.html#val-current" title="Fiber.current">current</a> fiber.</p><p>As a data point, in a benchmark that increments an <code>int ref</code> protected by a mutex, obtaining the fiber identity for the lock and unlock operations — that only need it for error checking purposes — roughly tripled the cost of an increment on a machine.</p><p>Using GADTs internally allows an optional fiber to be provided without adding overhead to operations on non-optional fibers and allows optional fibers to used without allocations at a very low cost.</p></div></body></html>
|