monoidal-synchronisation
Safe HaskellNone
LanguageHaskell2010

Data.Monoid.Synchronisation

Synopsis

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)

Constructors

FirstToFinish 

Fields

Instances

Instances details
Generic1 (FirstToFinish m :: Type -> Type) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 (FirstToFinish m :: Type -> Type) 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (FirstToFinish m :: Type -> Type) = D1 ('MetaData "FirstToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "FirstToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFirstToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 m)))

Methods

from1 :: FirstToFinish m a -> Rep1 (FirstToFinish m) a #

to1 :: Rep1 (FirstToFinish m) a -> FirstToFinish m a #

Contravariant m => Contravariant (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

contramap :: (a' -> a) -> FirstToFinish m a -> FirstToFinish m a' #

(>$) :: b -> FirstToFinish m b -> FirstToFinish m a #

Alternative m => Alternative (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Applicative m => Applicative (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

pure :: a -> FirstToFinish m a #

(<*>) :: FirstToFinish m (a -> b) -> FirstToFinish m a -> FirstToFinish m b #

liftA2 :: (a -> b -> c) -> FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m c #

(*>) :: FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b #

(<*) :: FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m a #

Functor m => Functor (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fmap :: (a -> b) -> FirstToFinish m a -> FirstToFinish m b #

(<$) :: a -> FirstToFinish m b -> FirstToFinish m a #

Monad m => Monad (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(>>=) :: FirstToFinish m a -> (a -> FirstToFinish m b) -> FirstToFinish m b #

(>>) :: FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b #

return :: a -> FirstToFinish m a #

MonadPlus m => MonadPlus (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Foldable m => Foldable (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fold :: Monoid m0 => FirstToFinish m m0 -> m0 #

foldMap :: Monoid m0 => (a -> m0) -> FirstToFinish m a -> m0 #

foldMap' :: Monoid m0 => (a -> m0) -> FirstToFinish m a -> m0 #

foldr :: (a -> b -> b) -> b -> FirstToFinish m a -> b #

foldr' :: (a -> b -> b) -> b -> FirstToFinish m a -> b #

foldl :: (b -> a -> b) -> b -> FirstToFinish m a -> b #

foldl' :: (b -> a -> b) -> b -> FirstToFinish m a -> b #

foldr1 :: (a -> a -> a) -> FirstToFinish m a -> a #

foldl1 :: (a -> a -> a) -> FirstToFinish m a -> a #

toList :: FirstToFinish m a -> [a] #

null :: FirstToFinish m a -> Bool #

length :: FirstToFinish m a -> Int #

elem :: Eq a => a -> FirstToFinish m a -> Bool #

maximum :: Ord a => FirstToFinish m a -> a #

minimum :: Ord a => FirstToFinish m a -> a #

sum :: Num a => FirstToFinish m a -> a #

product :: Num a => FirstToFinish m a -> a #

Traversable m => Traversable (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

traverse :: Applicative f => (a -> f b) -> FirstToFinish m a -> f (FirstToFinish m b) #

sequenceA :: Applicative f => FirstToFinish m (f a) -> f (FirstToFinish m a) #

mapM :: Monad m0 => (a -> m0 b) -> FirstToFinish m a -> m0 (FirstToFinish m b) #

sequence :: Monad m0 => FirstToFinish m (m0 a) -> m0 (FirstToFinish m a) #

Alternative m => Monoid (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Alternative m => Semigroup (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Generic (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep (FirstToFinish m a) 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep (FirstToFinish m a) = D1 ('MetaData "FirstToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "FirstToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFirstToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a))))

Methods

from :: FirstToFinish m a -> Rep (FirstToFinish m a) x #

to :: Rep (FirstToFinish m a) x -> FirstToFinish m a #

type Rep1 (FirstToFinish m :: Type -> Type) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (FirstToFinish m :: Type -> Type) = D1 ('MetaData "FirstToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "FirstToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFirstToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 m)))
type Rep (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep (FirstToFinish m a) = D1 ('MetaData "FirstToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.6-inplace" 'True) (C1 ('MetaCons "FirstToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFirstToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a))))

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'

Constructors

LastToFinish 

Fields

Instances

Instances details
Generic1 (LastToFinish m :: Type -> Type) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 (LastToFinish m :: Type -> Type) 
Instance details

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)))

Methods

from1 :: LastToFinish m a -> Rep1 (LastToFinish m) a #

to1 :: Rep1 (LastToFinish m) a -> LastToFinish m a #

Alternative m => Alternative (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fmap :: (a -> b) -> LastToFinish m a -> LastToFinish m b #

(<$) :: a -> LastToFinish m b -> LastToFinish m a #

Monad m => Monad (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(>>=) :: 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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

mzero :: LastToFinish m a #

mplus :: LastToFinish m a -> LastToFinish m a -> LastToFinish m a #

Foldable m => Foldable (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(<>) :: 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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep (LastToFinish m a) 
Instance details

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))))

Methods

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 # 
Instance details

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 # 
Instance details

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)

Constructors

LastToFinishM 

Fields

Instances

Instances details
Generic1 (LastToFinishM m :: Type -> Type) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 (LastToFinishM m :: Type -> Type) 
Instance details

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)))

Methods

from1 :: LastToFinishM m a -> Rep1 (LastToFinishM m) a #

to1 :: Rep1 (LastToFinishM m) a -> LastToFinishM m a #

Alternative m => Alternative (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Applicative m => Applicative (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fmap :: (a -> b) -> LastToFinishM m a -> LastToFinishM m b #

(<$) :: a -> LastToFinishM m b -> LastToFinishM m a #

Monad m => Monad (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(>>=) :: 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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Foldable m => Foldable (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

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 # 
Instance details

Defined in Data.Monoid.Synchronisation

(Applicative m, Semigroup a) => Semigroup (LastToFinishM m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Generic (LastToFinishM m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep (LastToFinishM m a) 
Instance details

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))))

Methods

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 # 
Instance details

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 # 
Instance details

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 #