monoidal-synchronisation-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Data.Monoid.Synchronisation

Synopsis

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)

Constructors

FirstToFinish 

Fields

Instances

Instances details
Monad m ⇒ Monad (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(>>=)FirstToFinish m a → (a → FirstToFinish m b) → FirstToFinish m b Source #

(>>)FirstToFinish m a → FirstToFinish m b → FirstToFinish m b Source #

return ∷ a → FirstToFinish m a Source #

Functor m ⇒ Functor (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fmap ∷ (a → b) → FirstToFinish m a → FirstToFinish m b Source #

(<$) ∷ a → FirstToFinish m b → FirstToFinish m a Source #

Applicative m ⇒ Applicative (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

pure ∷ a → FirstToFinish m a Source #

(<*>)FirstToFinish m (a → b) → FirstToFinish m a → FirstToFinish m b Source #

liftA2 ∷ (a → b → c) → FirstToFinish m a → FirstToFinish m b → FirstToFinish m c Source #

(*>)FirstToFinish m a → FirstToFinish m b → FirstToFinish m b Source #

(<*)FirstToFinish m a → FirstToFinish m b → FirstToFinish m a Source #

Foldable m ⇒ Foldable (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

foldMonoid m0 ⇒ FirstToFinish m m0 → m0 Source #

foldMapMonoid m0 ⇒ (a → m0) → FirstToFinish m a → m0 Source #

foldMap'Monoid m0 ⇒ (a → m0) → FirstToFinish m a → m0 Source #

foldr ∷ (a → b → b) → b → FirstToFinish m a → b Source #

foldr' ∷ (a → b → b) → b → FirstToFinish m a → b Source #

foldl ∷ (b → a → b) → b → FirstToFinish m a → b Source #

foldl' ∷ (b → a → b) → b → FirstToFinish m a → b Source #

foldr1 ∷ (a → a → a) → FirstToFinish m a → a Source #

foldl1 ∷ (a → a → a) → FirstToFinish m a → a Source #

toListFirstToFinish m a → [a] Source #

nullFirstToFinish m a → Bool Source #

lengthFirstToFinish m a → Int Source #

elemEq a ⇒ a → FirstToFinish m a → Bool Source #

maximumOrd a ⇒ FirstToFinish m a → a Source #

minimumOrd a ⇒ FirstToFinish m a → a Source #

sumNum a ⇒ FirstToFinish m a → a Source #

productNum a ⇒ FirstToFinish m a → a Source #

Traversable m ⇒ Traversable (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

traverseApplicative f ⇒ (a → f b) → FirstToFinish m a → f (FirstToFinish m b) Source #

sequenceAApplicative f ⇒ FirstToFinish m (f a) → f (FirstToFinish m a) Source #

mapMMonad m0 ⇒ (a → m0 b) → FirstToFinish m a → m0 (FirstToFinish m b) Source #

sequenceMonad m0 ⇒ FirstToFinish m (m0 a) → m0 (FirstToFinish m a) Source #

Contravariant m ⇒ Contravariant (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

contramap ∷ (a → b) → FirstToFinish m b → FirstToFinish m a Source #

(>$) ∷ b → FirstToFinish m b → FirstToFinish m a Source #

Alternative m ⇒ Alternative (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

MonadPlus m ⇒ MonadPlus (FirstToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Generic1 (FirstToFinish m ∷ TypeType) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 (FirstToFinish m) ∷ k → Type Source #

Methods

from1 ∷ ∀ (a ∷ k). FirstToFinish m a → Rep1 (FirstToFinish m) a Source #

to1 ∷ ∀ (a ∷ k). Rep1 (FirstToFinish m) a → FirstToFinish m a Source #

Generic (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep (FirstToFinish m a) ∷ TypeType Source #

Methods

fromFirstToFinish m a → Rep (FirstToFinish m a) x Source #

toRep (FirstToFinish m a) x → FirstToFinish m a Source #

Alternative m ⇒ Semigroup (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Alternative m ⇒ Monoid (FirstToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (FirstToFinish m ∷ TypeType) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (FirstToFinish m ∷ TypeType) = D1 ('MetaData "FirstToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.0-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.0-inplace" 'True) (C1 ('MetaCons "FirstToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFirstToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a))))

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'

Constructors

LastToFinish 

Fields

Instances

Instances details
Monad m ⇒ Monad (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(>>=)LastToFinish m a → (a → LastToFinish m b) → LastToFinish m b Source #

(>>)LastToFinish m a → LastToFinish m b → LastToFinish m b Source #

return ∷ a → LastToFinish m a Source #

Functor m ⇒ Functor (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fmap ∷ (a → b) → LastToFinish m a → LastToFinish m b Source #

(<$) ∷ a → LastToFinish m b → LastToFinish m a Source #

Applicative m ⇒ Applicative (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

pure ∷ a → LastToFinish m a Source #

(<*>)LastToFinish m (a → b) → LastToFinish m a → LastToFinish m b Source #

liftA2 ∷ (a → b → c) → LastToFinish m a → LastToFinish m b → LastToFinish m c Source #

(*>)LastToFinish m a → LastToFinish m b → LastToFinish m b Source #

(<*)LastToFinish m a → LastToFinish m b → LastToFinish m a Source #

Foldable m ⇒ Foldable (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

foldMonoid m0 ⇒ LastToFinish m m0 → m0 Source #

foldMapMonoid m0 ⇒ (a → m0) → LastToFinish m a → m0 Source #

foldMap'Monoid m0 ⇒ (a → m0) → LastToFinish m a → m0 Source #

foldr ∷ (a → b → b) → b → LastToFinish m a → b Source #

foldr' ∷ (a → b → b) → b → LastToFinish m a → b Source #

foldl ∷ (b → a → b) → b → LastToFinish m a → b Source #

foldl' ∷ (b → a → b) → b → LastToFinish m a → b Source #

foldr1 ∷ (a → a → a) → LastToFinish m a → a Source #

foldl1 ∷ (a → a → a) → LastToFinish m a → a Source #

toListLastToFinish m a → [a] Source #

nullLastToFinish m a → Bool Source #

lengthLastToFinish m a → Int Source #

elemEq a ⇒ a → LastToFinish m a → Bool Source #

maximumOrd a ⇒ LastToFinish m a → a Source #

minimumOrd a ⇒ LastToFinish m a → a Source #

sumNum a ⇒ LastToFinish m a → a Source #

productNum a ⇒ LastToFinish m a → a Source #

Traversable m ⇒ Traversable (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

traverseApplicative f ⇒ (a → f b) → LastToFinish m a → f (LastToFinish m b) Source #

sequenceAApplicative f ⇒ LastToFinish m (f a) → f (LastToFinish m a) Source #

mapMMonad m0 ⇒ (a → m0 b) → LastToFinish m a → m0 (LastToFinish m b) Source #

sequenceMonad m0 ⇒ LastToFinish m (m0 a) → m0 (LastToFinish m a) Source #

Alternative m ⇒ Alternative (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

MonadPlus m ⇒ MonadPlus (LastToFinish m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Generic1 (LastToFinish m ∷ TypeType) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 (LastToFinish m) ∷ k → Type Source #

Methods

from1 ∷ ∀ (a ∷ k). LastToFinish m a → Rep1 (LastToFinish m) a Source #

to1 ∷ ∀ (a ∷ k). Rep1 (LastToFinish m) a → LastToFinish m a Source #

Generic (LastToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep (LastToFinish m a) ∷ TypeType Source #

Methods

fromLastToFinish m a → Rep (LastToFinish m a) x Source #

toRep (LastToFinish m a) x → LastToFinish m a Source #

MonadPlus m ⇒ Semigroup (LastToFinish m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(<>)LastToFinish m a → LastToFinish m a → LastToFinish m a Source #

sconcatNonEmpty (LastToFinish m a) → LastToFinish m a Source #

stimesIntegral b ⇒ b → LastToFinish m a → LastToFinish m a Source #

type Rep1 (LastToFinish m ∷ TypeType) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (LastToFinish m ∷ TypeType) = D1 ('MetaData "LastToFinish" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.0-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.0-inplace" 'True) (C1 ('MetaCons "LastToFinish" 'PrefixI 'True) (S1 ('MetaSel ('Just "runLastToFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a))))

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)

Constructors

LastToFinishM 

Fields

Instances

Instances details
Monad m ⇒ Monad (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

(>>=)LastToFinishM m a → (a → LastToFinishM m b) → LastToFinishM m b Source #

(>>)LastToFinishM m a → LastToFinishM m b → LastToFinishM m b Source #

return ∷ a → LastToFinishM m a Source #

Functor m ⇒ Functor (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

fmap ∷ (a → b) → LastToFinishM m a → LastToFinishM m b Source #

(<$) ∷ a → LastToFinishM m b → LastToFinishM m a Source #

Applicative m ⇒ Applicative (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

pure ∷ a → LastToFinishM m a Source #

(<*>)LastToFinishM m (a → b) → LastToFinishM m a → LastToFinishM m b Source #

liftA2 ∷ (a → b → c) → LastToFinishM m a → LastToFinishM m b → LastToFinishM m c Source #

(*>)LastToFinishM m a → LastToFinishM m b → LastToFinishM m b Source #

(<*)LastToFinishM m a → LastToFinishM m b → LastToFinishM m a Source #

Foldable m ⇒ Foldable (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

foldMonoid m0 ⇒ LastToFinishM m m0 → m0 Source #

foldMapMonoid m0 ⇒ (a → m0) → LastToFinishM m a → m0 Source #

foldMap'Monoid m0 ⇒ (a → m0) → LastToFinishM m a → m0 Source #

foldr ∷ (a → b → b) → b → LastToFinishM m a → b Source #

foldr' ∷ (a → b → b) → b → LastToFinishM m a → b Source #

foldl ∷ (b → a → b) → b → LastToFinishM m a → b Source #

foldl' ∷ (b → a → b) → b → LastToFinishM m a → b Source #

foldr1 ∷ (a → a → a) → LastToFinishM m a → a Source #

foldl1 ∷ (a → a → a) → LastToFinishM m a → a Source #

toListLastToFinishM m a → [a] Source #

nullLastToFinishM m a → Bool Source #

lengthLastToFinishM m a → Int Source #

elemEq a ⇒ a → LastToFinishM m a → Bool Source #

maximumOrd a ⇒ LastToFinishM m a → a Source #

minimumOrd a ⇒ LastToFinishM m a → a Source #

sumNum a ⇒ LastToFinishM m a → a Source #

productNum a ⇒ LastToFinishM m a → a Source #

Traversable m ⇒ Traversable (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Methods

traverseApplicative f ⇒ (a → f b) → LastToFinishM m a → f (LastToFinishM m b) Source #

sequenceAApplicative f ⇒ LastToFinishM m (f a) → f (LastToFinishM m a) Source #

mapMMonad m0 ⇒ (a → m0 b) → LastToFinishM m a → m0 (LastToFinishM m b) Source #

sequenceMonad m0 ⇒ LastToFinishM m (m0 a) → m0 (LastToFinishM m a) Source #

Alternative m ⇒ Alternative (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

MonadPlus m ⇒ MonadPlus (LastToFinishM m) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Generic1 (LastToFinishM m ∷ TypeType) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 (LastToFinishM m) ∷ k → Type Source #

Methods

from1 ∷ ∀ (a ∷ k). LastToFinishM m a → Rep1 (LastToFinishM m) a Source #

to1 ∷ ∀ (a ∷ k). Rep1 (LastToFinishM m) a → LastToFinishM m a Source #

Generic (LastToFinishM m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep (LastToFinishM m a) ∷ TypeType Source #

Methods

fromLastToFinishM m a → Rep (LastToFinishM m a) x Source #

toRep (LastToFinishM m a) x → LastToFinishM m a Source #

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

Defined in Data.Monoid.Synchronisation

(Applicative m, Monoid a) ⇒ Monoid (LastToFinishM m a) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (LastToFinishM m ∷ TypeType) Source # 
Instance details

Defined in Data.Monoid.Synchronisation

type Rep1 (LastToFinishM m ∷ TypeType) = D1 ('MetaData "LastToFinishM" "Data.Monoid.Synchronisation" "monoidal-synchronisation-0.1.0.0-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.0-inplace" 'True) (C1 ('MetaCons "LastToFinishM" 'PrefixI 'True) (S1 ('MetaSel ('Just "runLastToFinishM") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a))))