package picos
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=3f5a08199cf65c2dae2f7d68f3877178f1da8eabf5376e15114e5a8958087dfa
sha512=ad24910c47ce614268c4268874bb918da7f8b5f03b3ad706bbf30323635262e94ddab6be24eaebbca706bfa82c0a517d4272b396459e020c185942125c9bdb7b
doc/picos/Picos/Fiber/Maybe/index.html
Module Fiber.Maybe
Source
An unboxed optional fiber.
of_fiber fiber
casts the fiber into an optional fiber.
🏎️ This performs no allocations.
current_if checked
returns nothing
in case checked
is Some false
and otherwise of_fiber (Fiber.current ())
.
current_check_if checked
returns nothing
in case checked
is Some false
and otherwise of_fiber (Fiber.current ())
and also calls Fiber.check
on the fiber.
or_current maybe
returns of_fiber (Fiber.current ())
in case maybe
is nothing
and otherwise returns maybe
.
to_fiber_or_current maybe
returns Fiber.current ()
in case maybe
is nothing
and otherwise returns the fiber that maybe
was cast from.
check maybe
returns immediately if maybe
is nothing
and otherwise calls Fiber.check
on the fiber.
equal l r
determines whether l
and r
are maybe equal. Specifically, if either l
or r
or both is nothing
, then they are considered (maybe) equal. Otherwise l
and r
are compared for physical equality.
equal l r
determines whether l
and r
are maybe unequal. Specifically, if either l
or r
or both is nothing
, then they are considered (maybe) unequal. Otherwise l
and r
are compared for physical equality.
Design rationale
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 current fiber.
As a data point, in a benchmark that increments an int ref
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.
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.