Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
-
newtype
FirstToFinish
m a =
FirstToFinish
{
- runFirstToFinish :: m a
-
newtype
LastToFinish
m a =
LastToFinish
{
- runLastToFinish :: m a
- firstToLast :: FirstToFinish m a -> LastToFinish m a
- lastToFirst :: LastToFinish m a -> FirstToFinish m a
-
newtype
LastToFinishM
m a =
LastToFinishM
{
- runLastToFinishM :: m a
- firstToLastM :: FirstToFinish m a -> LastToFinishM m a
- lastToFirstM :: LastToFinishM m a -> FirstToFinish m a
Documentation
newtype FirstToFinish m a Source #
First-to-finish synchronisation. Like
Alt
it is a monoid under
<|>
.
First-to-finish is the additive monoid of
near-semiring
for which
multiplication is given by
LastToFinish
.
-- | Return first available value. -- readFirstMVar :: [TMVar a] -> STM a readFirstMVar = runFirstToFinish . foldMap (FirstToFinish . readTMVar)
FirstToFinish | |
|
Instances
newtype LastToFinish m a Source #
Last-to-finish synchronisation. It is the multiplicative semigroup of
the
near-semiring
for which addition is
given by
FirstToFinish
.
This is similar to
Ap
(see
LastToFinishM
) in the sense that it will wait
for all monadic effects, but unlike
Ap
it will not combine all results
using a monoid instance, but rather it will return the last one. Also unlike
Ap
it does not have a monoidal unit.
-- | Read all 'TMVar's and return the one that was filled last. -- readAllTMVars :: Monoid a => NonEmpty (TMVar a) -> STM a readAllTMVars = runLastToFinish . foldMap1 (LastToFinish . readTMVar) -- from 'semigroupoids' package or use 'foldr1' and 'fmap' -- from 'base'
LastToFinish | |
|
Instances
firstToLast :: FirstToFinish m a -> LastToFinish m a Source #
lastToFirst :: LastToFinish m a -> FirstToFinish m a Source #
newtype LastToFinishM m a Source #
Last-to-finish synchronisation. Like
Ap
it is a monoid under
<*>
.
The advantage over
LastToFinish
is that it has a
Monoid
instance, but
a
must be a
Monoid
as well.
LastToFinishM
and
FirstToFinish
form
a unitial near-ring when
m ~ STM
.
-- | Read all 'TMVar's and combine the result using 'Monoid' instance. -- readAllTMVars :: Monoid a => [TMVar a] -> STM a readAllTMVars = runLastToFinish . foldMap (LastToFinish . readTMVar)
LastToFinishM | |
|
Instances
firstToLastM :: FirstToFinish m a -> LastToFinishM m a Source #
lastToFirstM :: LastToFinishM m a -> FirstToFinish m a Source #