Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype FirstToFinish (m :: Type -> Type) a = FirstToFinish {
- runFirstToFinish :: m a
- newtype LastToFinish (m :: Type -> Type) a = LastToFinish {
- runLastToFinish :: m a
- firstToLast :: forall (m :: Type -> Type) a. FirstToFinish m a -> LastToFinish m a
- lastToFirst :: forall (m :: Type -> Type) a. LastToFinish m a -> FirstToFinish m a
- newtype LastToFinishM (m :: Type -> Type) a = LastToFinishM {
- runLastToFinishM :: m a
- firstToLastM :: forall (m :: Type -> Type) a. FirstToFinish m a -> LastToFinishM m a
- lastToFirstM :: forall (m :: Type -> Type) a. LastToFinishM m a -> FirstToFinish m a
Documentation
newtype FirstToFinish (m :: Type -> Type) 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 :: Type -> Type) 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
Generic1 (LastToFinish m :: Type -> Type) Source # | |||||
Defined in Data.Monoid.Synchronisation
from1 :: LastToFinish m a -> Rep1 (LastToFinish m) a # to1 :: Rep1 (LastToFinish m) a -> LastToFinish m a # | |||||
Alternative m => Alternative (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation empty :: LastToFinish m a # (<|>) :: LastToFinish m a -> LastToFinish m a -> LastToFinish m a # some :: LastToFinish m a -> LastToFinish m [a] # many :: LastToFinish m a -> LastToFinish m [a] # | |||||
Applicative m => Applicative (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation pure :: a -> LastToFinish m a # (<*>) :: LastToFinish m (a -> b) -> LastToFinish m a -> LastToFinish m b # liftA2 :: (a -> b -> c) -> LastToFinish m a -> LastToFinish m b -> LastToFinish m c # (*>) :: LastToFinish m a -> LastToFinish m b -> LastToFinish m b # (<*) :: LastToFinish m a -> LastToFinish m b -> LastToFinish m a # | |||||
Functor m => Functor (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation fmap :: (a -> b) -> LastToFinish m a -> LastToFinish m b # (<$) :: a -> LastToFinish m b -> LastToFinish m a # | |||||
Monad m => Monad (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation (>>=) :: LastToFinish m a -> (a -> LastToFinish m b) -> LastToFinish m b # (>>) :: LastToFinish m a -> LastToFinish m b -> LastToFinish m b # return :: a -> LastToFinish m a # | |||||
MonadPlus m => MonadPlus (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation mzero :: LastToFinish m a # mplus :: LastToFinish m a -> LastToFinish m a -> LastToFinish m a # | |||||
Foldable m => Foldable (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation fold :: Monoid m0 => LastToFinish m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> LastToFinish m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> LastToFinish m a -> m0 # foldr :: (a -> b -> b) -> b -> LastToFinish m a -> b # foldr' :: (a -> b -> b) -> b -> LastToFinish m a -> b # foldl :: (b -> a -> b) -> b -> LastToFinish m a -> b # foldl' :: (b -> a -> b) -> b -> LastToFinish m a -> b # foldr1 :: (a -> a -> a) -> LastToFinish m a -> a # foldl1 :: (a -> a -> a) -> LastToFinish m a -> a # toList :: LastToFinish m a -> [a] # null :: LastToFinish m a -> Bool # length :: LastToFinish m a -> Int # elem :: Eq a => a -> LastToFinish m a -> Bool # maximum :: Ord a => LastToFinish m a -> a # minimum :: Ord a => LastToFinish m a -> a # sum :: Num a => LastToFinish m a -> a # product :: Num a => LastToFinish m a -> a # | |||||
Traversable m => Traversable (LastToFinish m) Source # | |||||
Defined in Data.Monoid.Synchronisation traverse :: Applicative f => (a -> f b) -> LastToFinish m a -> f (LastToFinish m b) # sequenceA :: Applicative f => LastToFinish m (f a) -> f (LastToFinish m a) # mapM :: Monad m0 => (a -> m0 b) -> LastToFinish m a -> m0 (LastToFinish m b) # sequence :: Monad m0 => LastToFinish m (m0 a) -> m0 (LastToFinish m a) # | |||||
MonadPlus m => Semigroup (LastToFinish m a) Source # | |||||
Defined in Data.Monoid.Synchronisation (<>) :: LastToFinish m a -> LastToFinish m a -> LastToFinish m a # sconcat :: NonEmpty (LastToFinish m a) -> LastToFinish m a # stimes :: Integral b => b -> LastToFinish m a -> LastToFinish m a # | |||||
Generic (LastToFinish m a) Source # | |||||
Defined in Data.Monoid.Synchronisation
from :: LastToFinish m a -> Rep (LastToFinish m a) x # to :: Rep (LastToFinish m a) x -> LastToFinish m a # | |||||
type Rep1 (LastToFinish m :: Type -> Type) Source # | |||||
Defined in Data.Monoid.Synchronisation type Rep1 (LastToFinish m :: Type -> Type) = D1 ('MetaData "LastToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "LastToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runLastToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 m))) | |||||
type Rep (LastToFinish m a) Source # | |||||
Defined in Data.Monoid.Synchronisation type Rep (LastToFinish m a) = D1 ('MetaData "LastToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "LastToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runLastToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a)))) |
firstToLast :: forall (m :: Type -> Type) a. FirstToFinish m a -> LastToFinish m a Source #
lastToFirst :: forall (m :: Type -> Type) a. LastToFinish m a -> FirstToFinish m a Source #
newtype LastToFinishM (m :: Type -> Type) 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
Generic1 (LastToFinishM m :: Type -> Type) Source # | |||||
Defined in Data.Monoid.Synchronisation
from1 :: LastToFinishM m a -> Rep1 (LastToFinishM m) a # to1 :: Rep1 (LastToFinishM m) a -> LastToFinishM m a # | |||||
Alternative m => Alternative (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation empty :: LastToFinishM m a # (<|>) :: LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a # some :: LastToFinishM m a -> LastToFinishM m [a] # many :: LastToFinishM m a -> LastToFinishM m [a] # | |||||
Applicative m => Applicative (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation pure :: a -> LastToFinishM m a # (<*>) :: LastToFinishM m (a -> b) -> LastToFinishM m a -> LastToFinishM m b # liftA2 :: (a -> b -> c) -> LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m c # (*>) :: LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b # (<*) :: LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m a # | |||||
Functor m => Functor (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation fmap :: (a -> b) -> LastToFinishM m a -> LastToFinishM m b # (<$) :: a -> LastToFinishM m b -> LastToFinishM m a # | |||||
Monad m => Monad (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation (>>=) :: LastToFinishM m a -> (a -> LastToFinishM m b) -> LastToFinishM m b # (>>) :: LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b # return :: a -> LastToFinishM m a # | |||||
MonadPlus m => MonadPlus (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation mzero :: LastToFinishM m a # mplus :: LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a # | |||||
Foldable m => Foldable (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation fold :: Monoid m0 => LastToFinishM m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> LastToFinishM m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> LastToFinishM m a -> m0 # foldr :: (a -> b -> b) -> b -> LastToFinishM m a -> b # foldr' :: (a -> b -> b) -> b -> LastToFinishM m a -> b # foldl :: (b -> a -> b) -> b -> LastToFinishM m a -> b # foldl' :: (b -> a -> b) -> b -> LastToFinishM m a -> b # foldr1 :: (a -> a -> a) -> LastToFinishM m a -> a # foldl1 :: (a -> a -> a) -> LastToFinishM m a -> a # toList :: LastToFinishM m a -> [a] # null :: LastToFinishM m a -> Bool # length :: LastToFinishM m a -> Int # elem :: Eq a => a -> LastToFinishM m a -> Bool # maximum :: Ord a => LastToFinishM m a -> a # minimum :: Ord a => LastToFinishM m a -> a # sum :: Num a => LastToFinishM m a -> a # product :: Num a => LastToFinishM m a -> a # | |||||
Traversable m => Traversable (LastToFinishM m) Source # | |||||
Defined in Data.Monoid.Synchronisation traverse :: Applicative f => (a -> f b) -> LastToFinishM m a -> f (LastToFinishM m b) # sequenceA :: Applicative f => LastToFinishM m (f a) -> f (LastToFinishM m a) # mapM :: Monad m0 => (a -> m0 b) -> LastToFinishM m a -> m0 (LastToFinishM m b) # sequence :: Monad m0 => LastToFinishM m (m0 a) -> m0 (LastToFinishM m a) # | |||||
(Applicative m, Monoid a) => Monoid (LastToFinishM m a) Source # | |||||
Defined in Data.Monoid.Synchronisation mempty :: LastToFinishM m a # mappend :: LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a # mconcat :: [LastToFinishM m a] -> LastToFinishM m a # | |||||
(Applicative m, Semigroup a) => Semigroup (LastToFinishM m a) Source # | |||||
Defined in Data.Monoid.Synchronisation (<>) :: LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a # sconcat :: NonEmpty (LastToFinishM m a) -> LastToFinishM m a # stimes :: Integral b => b -> LastToFinishM m a -> LastToFinishM m a # | |||||
Generic (LastToFinishM m a) Source # | |||||
Defined in Data.Monoid.Synchronisation
from :: LastToFinishM m a -> Rep (LastToFinishM m a) x # to :: Rep (LastToFinishM m a) x -> LastToFinishM m a # | |||||
type Rep1 (LastToFinishM m :: Type -> Type) Source # | |||||
Defined in Data.Monoid.Synchronisation type Rep1 (LastToFinishM m :: Type -> Type) = D1 ('MetaData "LastToFinishM" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "LastToFinishM" 'PrefixI 'True) (S1 ('MetaSel ('Just "runLastToFinishM") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 m))) | |||||
type Rep (LastToFinishM m a) Source # | |||||
Defined in Data.Monoid.Synchronisation type Rep (LastToFinishM m a) = D1 ('MetaData "LastToFinishM" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "LastToFinishM" 'PrefixI 'True) (S1 ('MetaSel ('Just "runLastToFinishM") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a)))) |
firstToLastM :: forall (m :: Type -> Type) a. FirstToFinish m a -> LastToFinishM m a Source #
lastToFirstM :: forall (m :: Type -> Type) a. LastToFinishM m a -> FirstToFinish m a Source #