monoidal-synchronisation-0.1.0.1
Safe Haskell None
Language Haskell2010

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

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

Associated Types

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

Generic ( FirstToFinish m a) Source #
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep ( FirstToFinish m a) :: Type -> Type 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 :: 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.1-DikVxJZKIrcFnSuUOiLlPL" ' 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.1-DikVxJZKIrcFnSuUOiLlPL" ' 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

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 ( LastToFinish m) :: k -> Type Source #

Generic ( LastToFinish m a) Source #
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep ( LastToFinish m a) :: Type -> Type Source #

MonadPlus m => Semigroup ( LastToFinish m a) Source #
Instance details

Defined in Data.Monoid.Synchronisation

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.1-DikVxJZKIrcFnSuUOiLlPL" ' 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.1-DikVxJZKIrcFnSuUOiLlPL" ' 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

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

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

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep1 ( LastToFinishM m) :: k -> Type Source #

Generic ( LastToFinishM m a) Source #
Instance details

Defined in Data.Monoid.Synchronisation

Associated Types

type Rep ( LastToFinishM m a) :: Type -> Type 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 :: 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.1-DikVxJZKIrcFnSuUOiLlPL" ' 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.1-DikVxJZKIrcFnSuUOiLlPL" ' True ) ( C1 (' MetaCons "LastToFinishM" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "runLastToFinishM") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 (m a))))