{-# LANGUAGE DeriveFunctor              #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE DerivingVia                #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveTraversable          #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE StandaloneDeriving         #-}

module Data.Monoid.Synchronisation
  ( FirstToFinish (..)
  , LastToFinish (..)
  , firstToLast
  , lastToFirst
  , LastToFinishM (..)
  , firstToLastM
  , lastToFirstM
  ) where

import           Data.Coerce (coerce)
import           Data.Functor.Contravariant (Contravariant)
import           Data.Monoid (Alt (..), Ap (..))
import           GHC.Generics (Generic, Generic1)

import           Control.Applicative (Alternative (..))
import           Control.Monad (MonadPlus (..))


-- | First-to-finish synchronisation.  Like 'Alt' it is a monoid under '<|>'.
-- First-to-finish is the additive monoid of
-- [near-semiring](https://www.wikiwand.com/en/Near-semiring) for which
-- multiplication is given by 'LastToFinish'.
--
-- > -- | Return first available value.
-- > --
-- > readFirstMVar :: [TMVar a] -> STM a
-- > readFirstMVar = runFirstToFinish
-- >               . foldMap (FirstToFinish . readTMVar)
--
--
newtype FirstToFinish m a = FirstToFinish { forall (m :: * -> *) a. FirstToFinish m a -> m a
runFirstToFinish :: m a }
  deriving newtype (forall a b. (a -> b) -> FirstToFinish m a -> FirstToFinish m b)
-> (forall a b. a -> FirstToFinish m b -> FirstToFinish m a)
-> Functor (FirstToFinish m)
forall a b. a -> FirstToFinish m b -> FirstToFinish m a
forall a b. (a -> b) -> FirstToFinish m a -> FirstToFinish m b
forall (m :: * -> *) a b.
Functor m =>
a -> FirstToFinish m b -> FirstToFinish m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> FirstToFinish m a -> FirstToFinish m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> FirstToFinish m a -> FirstToFinish m b
fmap :: forall a b. (a -> b) -> FirstToFinish m a -> FirstToFinish m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> FirstToFinish m b -> FirstToFinish m a
<$ :: forall a b. a -> FirstToFinish m b -> FirstToFinish m a
Functor
  deriving         ( (forall x. FirstToFinish m a -> Rep (FirstToFinish m a) x)
-> (forall x. Rep (FirstToFinish m a) x -> FirstToFinish m a)
-> Generic (FirstToFinish m a)
forall x. Rep (FirstToFinish m a) x -> FirstToFinish m a
forall x. FirstToFinish m a -> Rep (FirstToFinish m a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: * -> *) a x.
Rep (FirstToFinish m a) x -> FirstToFinish m a
forall (m :: * -> *) a x.
FirstToFinish m a -> Rep (FirstToFinish m a) x
$cfrom :: forall (m :: * -> *) a x.
FirstToFinish m a -> Rep (FirstToFinish m a) x
from :: forall x. FirstToFinish m a -> Rep (FirstToFinish m a) x
$cto :: forall (m :: * -> *) a x.
Rep (FirstToFinish m a) x -> FirstToFinish m a
to :: forall x. Rep (FirstToFinish m a) x -> FirstToFinish m a
Generic
                   , (forall a. FirstToFinish m a -> Rep1 (FirstToFinish m) a)
-> (forall a. Rep1 (FirstToFinish m) a -> FirstToFinish m a)
-> Generic1 (FirstToFinish m)
forall a. Rep1 (FirstToFinish m) a -> FirstToFinish m a
forall a. FirstToFinish m a -> Rep1 (FirstToFinish m) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
forall (m :: * -> *) a.
Rep1 (FirstToFinish m) a -> FirstToFinish m a
forall (m :: * -> *) a.
FirstToFinish m a -> Rep1 (FirstToFinish m) a
$cfrom1 :: forall (m :: * -> *) a.
FirstToFinish m a -> Rep1 (FirstToFinish m) a
from1 :: forall a. FirstToFinish m a -> Rep1 (FirstToFinish m) a
$cto1 :: forall (m :: * -> *) a.
Rep1 (FirstToFinish m) a -> FirstToFinish m a
to1 :: forall a. Rep1 (FirstToFinish m) a -> FirstToFinish m a
Generic1
                   , Functor (FirstToFinish m)
Functor (FirstToFinish m) =>
(forall a. a -> FirstToFinish m a)
-> (forall a b.
    FirstToFinish m (a -> b) -> FirstToFinish m a -> FirstToFinish m b)
-> (forall a b c.
    (a -> b -> c)
    -> FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m c)
-> (forall a b.
    FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b)
-> (forall a b.
    FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m a)
-> Applicative (FirstToFinish m)
forall a. a -> FirstToFinish m a
forall a b.
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m a
forall a b.
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
forall a b.
FirstToFinish m (a -> b) -> FirstToFinish m a -> FirstToFinish m b
forall a b c.
(a -> b -> c)
-> FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (FirstToFinish m)
forall (m :: * -> *) a. Applicative m => a -> FirstToFinish m a
forall (m :: * -> *) a b.
Applicative m =>
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m a
forall (m :: * -> *) a b.
Applicative m =>
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
forall (m :: * -> *) a b.
Applicative m =>
FirstToFinish m (a -> b) -> FirstToFinish m a -> FirstToFinish m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m c
$cpure :: forall (m :: * -> *) a. Applicative m => a -> FirstToFinish m a
pure :: forall a. a -> FirstToFinish m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
FirstToFinish m (a -> b) -> FirstToFinish m a -> FirstToFinish m b
<*> :: forall a b.
FirstToFinish m (a -> b) -> FirstToFinish m a -> FirstToFinish m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m c
liftA2 :: forall a b c.
(a -> b -> c)
-> FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
*> :: forall a b.
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m a
<* :: forall a b.
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m a
Applicative
                   , Applicative (FirstToFinish m)
Applicative (FirstToFinish m) =>
(forall a. FirstToFinish m a)
-> (forall a.
    FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a)
-> (forall a. FirstToFinish m a -> FirstToFinish m [a])
-> (forall a. FirstToFinish m a -> FirstToFinish m [a])
-> Alternative (FirstToFinish m)
forall a. FirstToFinish m a
forall a. FirstToFinish m a -> FirstToFinish m [a]
forall a.
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *).
Alternative m =>
Applicative (FirstToFinish m)
forall (m :: * -> *) a. Alternative m => FirstToFinish m a
forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m [a]
forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
$cempty :: forall (m :: * -> *) a. Alternative m => FirstToFinish m a
empty :: forall a. FirstToFinish m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
<|> :: forall a.
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
$csome :: forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m [a]
some :: forall a. FirstToFinish m a -> FirstToFinish m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m [a]
many :: forall a. FirstToFinish m a -> FirstToFinish m [a]
Alternative
                   , Applicative (FirstToFinish m)
Applicative (FirstToFinish m) =>
(forall a b.
 FirstToFinish m a -> (a -> FirstToFinish m b) -> FirstToFinish m b)
-> (forall a b.
    FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b)
-> (forall a. a -> FirstToFinish m a)
-> Monad (FirstToFinish m)
forall a. a -> FirstToFinish m a
forall a b.
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
forall a b.
FirstToFinish m a -> (a -> FirstToFinish m b) -> FirstToFinish m b
forall (m :: * -> *). Monad m => Applicative (FirstToFinish m)
forall (m :: * -> *) a. Monad m => a -> FirstToFinish m a
forall (m :: * -> *) a b.
Monad m =>
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
forall (m :: * -> *) a b.
Monad m =>
FirstToFinish m a -> (a -> FirstToFinish m b) -> FirstToFinish m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
FirstToFinish m a -> (a -> FirstToFinish m b) -> FirstToFinish m b
>>= :: forall a b.
FirstToFinish m a -> (a -> FirstToFinish m b) -> FirstToFinish m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
>> :: forall a b.
FirstToFinish m a -> FirstToFinish m b -> FirstToFinish m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> FirstToFinish m a
return :: forall a. a -> FirstToFinish m a
Monad
                   , Monad (FirstToFinish m)
Alternative (FirstToFinish m)
(Alternative (FirstToFinish m), Monad (FirstToFinish m)) =>
(forall a. FirstToFinish m a)
-> (forall a.
    FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a)
-> MonadPlus (FirstToFinish m)
forall a. FirstToFinish m a
forall a.
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
forall (m :: * -> *). MonadPlus m => Monad (FirstToFinish m)
forall (m :: * -> *). MonadPlus m => Alternative (FirstToFinish m)
forall (m :: * -> *) a. MonadPlus m => FirstToFinish m a
forall (m :: * -> *) a.
MonadPlus m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall (m :: * -> *) a. MonadPlus m => FirstToFinish m a
mzero :: forall a. FirstToFinish m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
mplus :: forall a.
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
MonadPlus
                   , Functor (FirstToFinish m)
Foldable (FirstToFinish m)
(Functor (FirstToFinish m), Foldable (FirstToFinish m)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> FirstToFinish m a -> f (FirstToFinish m b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    FirstToFinish m (f a) -> f (FirstToFinish m a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> FirstToFinish m a -> m (FirstToFinish m b))
-> (forall (m :: * -> *) a.
    Monad m =>
    FirstToFinish m (m a) -> m (FirstToFinish m a))
-> Traversable (FirstToFinish m)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *). Traversable m => Functor (FirstToFinish m)
forall (m :: * -> *). Traversable m => Foldable (FirstToFinish m)
forall (m :: * -> *) (m :: * -> *) a.
(Traversable m, Monad m) =>
FirstToFinish m (m a) -> m (FirstToFinish m a)
forall (m :: * -> *) (f :: * -> *) a.
(Traversable m, Applicative f) =>
FirstToFinish m (f a) -> f (FirstToFinish m a)
forall (m :: * -> *) (m :: * -> *) a b.
(Traversable m, Monad m) =>
(a -> m b) -> FirstToFinish m a -> m (FirstToFinish m b)
forall (m :: * -> *) (f :: * -> *) a b.
(Traversable m, Applicative f) =>
(a -> f b) -> FirstToFinish m a -> f (FirstToFinish m b)
forall (m :: * -> *) a.
Monad m =>
FirstToFinish m (m a) -> m (FirstToFinish m a)
forall (f :: * -> *) a.
Applicative f =>
FirstToFinish m (f a) -> f (FirstToFinish m a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FirstToFinish m a -> m (FirstToFinish m b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FirstToFinish m a -> f (FirstToFinish m b)
$ctraverse :: forall (m :: * -> *) (f :: * -> *) a b.
(Traversable m, Applicative f) =>
(a -> f b) -> FirstToFinish m a -> f (FirstToFinish m b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FirstToFinish m a -> f (FirstToFinish m b)
$csequenceA :: forall (m :: * -> *) (f :: * -> *) a.
(Traversable m, Applicative f) =>
FirstToFinish m (f a) -> f (FirstToFinish m a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
FirstToFinish m (f a) -> f (FirstToFinish m a)
$cmapM :: forall (m :: * -> *) (m :: * -> *) a b.
(Traversable m, Monad m) =>
(a -> m b) -> FirstToFinish m a -> m (FirstToFinish m b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FirstToFinish m a -> m (FirstToFinish m b)
$csequence :: forall (m :: * -> *) (m :: * -> *) a.
(Traversable m, Monad m) =>
FirstToFinish m (m a) -> m (FirstToFinish m a)
sequence :: forall (m :: * -> *) a.
Monad m =>
FirstToFinish m (m a) -> m (FirstToFinish m a)
Traversable
                   )
  deriving NonEmpty (FirstToFinish m a) -> FirstToFinish m a
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
(FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a)
-> (NonEmpty (FirstToFinish m a) -> FirstToFinish m a)
-> (forall b.
    Integral b =>
    b -> FirstToFinish m a -> FirstToFinish m a)
-> Semigroup (FirstToFinish m a)
forall b. Integral b => b -> FirstToFinish m a -> FirstToFinish m a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (m :: * -> *) a.
Alternative m =>
NonEmpty (FirstToFinish m a) -> FirstToFinish m a
forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
forall (m :: * -> *) a b.
(Alternative m, Integral b) =>
b -> FirstToFinish m a -> FirstToFinish m a
$c<> :: forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
<> :: FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
$csconcat :: forall (m :: * -> *) a.
Alternative m =>
NonEmpty (FirstToFinish m a) -> FirstToFinish m a
sconcat :: NonEmpty (FirstToFinish m a) -> FirstToFinish m a
$cstimes :: forall (m :: * -> *) a b.
(Alternative m, Integral b) =>
b -> FirstToFinish m a -> FirstToFinish m a
stimes :: forall b. Integral b => b -> FirstToFinish m a -> FirstToFinish m a
Semigroup     via (Alt m a)
  deriving Semigroup (FirstToFinish m a)
FirstToFinish m a
Semigroup (FirstToFinish m a) =>
FirstToFinish m a
-> (FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a)
-> ([FirstToFinish m a] -> FirstToFinish m a)
-> Monoid (FirstToFinish m a)
[FirstToFinish m a] -> FirstToFinish m a
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall (m :: * -> *) a.
Alternative m =>
Semigroup (FirstToFinish m a)
forall (m :: * -> *) a. Alternative m => FirstToFinish m a
forall (m :: * -> *) a.
Alternative m =>
[FirstToFinish m a] -> FirstToFinish m a
forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
$cmempty :: forall (m :: * -> *) a. Alternative m => FirstToFinish m a
mempty :: FirstToFinish m a
$cmappend :: forall (m :: * -> *) a.
Alternative m =>
FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
mappend :: FirstToFinish m a -> FirstToFinish m a -> FirstToFinish m a
$cmconcat :: forall (m :: * -> *) a.
Alternative m =>
[FirstToFinish m a] -> FirstToFinish m a
mconcat :: [FirstToFinish m a] -> FirstToFinish m a
Monoid        via (Alt m a)
  deriving (forall m. Monoid m => FirstToFinish m m -> m)
-> (forall m a. Monoid m => (a -> m) -> FirstToFinish m a -> m)
-> (forall m a. Monoid m => (a -> m) -> FirstToFinish m a -> m)
-> (forall a b. (a -> b -> b) -> b -> FirstToFinish m a -> b)
-> (forall a b. (a -> b -> b) -> b -> FirstToFinish m a -> b)
-> (forall b a. (b -> a -> b) -> b -> FirstToFinish m a -> b)
-> (forall b a. (b -> a -> b) -> b -> FirstToFinish m a -> b)
-> (forall a. (a -> a -> a) -> FirstToFinish m a -> a)
-> (forall a. (a -> a -> a) -> FirstToFinish m a -> a)
-> (forall a. FirstToFinish m a -> [a])
-> (forall a. FirstToFinish m a -> Bool)
-> (forall a. FirstToFinish m a -> Int)
-> (forall a. Eq a => a -> FirstToFinish m a -> Bool)
-> (forall a. Ord a => FirstToFinish m a -> a)
-> (forall a. Ord a => FirstToFinish m a -> a)
-> (forall a. Num a => FirstToFinish m a -> a)
-> (forall a. Num a => FirstToFinish m a -> a)
-> Foldable (FirstToFinish m)
forall a. Eq a => a -> FirstToFinish m a -> Bool
forall a. Num a => FirstToFinish m a -> a
forall a. Ord a => FirstToFinish m a -> a
forall m. Monoid m => FirstToFinish m m -> m
forall a. FirstToFinish m a -> Bool
forall a. FirstToFinish m a -> Int
forall a. FirstToFinish m a -> [a]
forall a. (a -> a -> a) -> FirstToFinish m a -> a
forall m a. Monoid m => (a -> m) -> FirstToFinish m a -> m
forall b a. (b -> a -> b) -> b -> FirstToFinish m a -> b
forall a b. (a -> b -> b) -> b -> FirstToFinish m a -> b
forall (m :: * -> *) a.
(Foldable m, Eq a) =>
a -> FirstToFinish m a -> Bool
forall (m :: * -> *) a.
(Foldable m, Num a) =>
FirstToFinish m a -> a
forall (m :: * -> *) a.
(Foldable m, Ord a) =>
FirstToFinish m a -> a
forall (m :: * -> *) m.
(Foldable m, Monoid m) =>
FirstToFinish m m -> m
forall (m :: * -> *) a. Foldable m => FirstToFinish m a -> Bool
forall (m :: * -> *) a. Foldable m => FirstToFinish m a -> Int
forall (m :: * -> *) a. Foldable m => FirstToFinish m a -> [a]
forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> FirstToFinish m a -> a
forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> FirstToFinish m a -> m
forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> FirstToFinish m a -> b
forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> FirstToFinish m a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (m :: * -> *) m.
(Foldable m, Monoid m) =>
FirstToFinish m m -> m
fold :: forall m. Monoid m => FirstToFinish m m -> m
$cfoldMap :: forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> FirstToFinish m a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> FirstToFinish m a -> m
$cfoldMap' :: forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> FirstToFinish m a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> FirstToFinish m a -> m
$cfoldr :: forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> FirstToFinish m a -> b
foldr :: forall a b. (a -> b -> b) -> b -> FirstToFinish m a -> b
$cfoldr' :: forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> FirstToFinish m a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> FirstToFinish m a -> b
$cfoldl :: forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> FirstToFinish m a -> b
foldl :: forall b a. (b -> a -> b) -> b -> FirstToFinish m a -> b
$cfoldl' :: forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> FirstToFinish m a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> FirstToFinish m a -> b
$cfoldr1 :: forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> FirstToFinish m a -> a
foldr1 :: forall a. (a -> a -> a) -> FirstToFinish m a -> a
$cfoldl1 :: forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> FirstToFinish m a -> a
foldl1 :: forall a. (a -> a -> a) -> FirstToFinish m a -> a
$ctoList :: forall (m :: * -> *) a. Foldable m => FirstToFinish m a -> [a]
toList :: forall a. FirstToFinish m a -> [a]
$cnull :: forall (m :: * -> *) a. Foldable m => FirstToFinish m a -> Bool
null :: forall a. FirstToFinish m a -> Bool
$clength :: forall (m :: * -> *) a. Foldable m => FirstToFinish m a -> Int
length :: forall a. FirstToFinish m a -> Int
$celem :: forall (m :: * -> *) a.
(Foldable m, Eq a) =>
a -> FirstToFinish m a -> Bool
elem :: forall a. Eq a => a -> FirstToFinish m a -> Bool
$cmaximum :: forall (m :: * -> *) a.
(Foldable m, Ord a) =>
FirstToFinish m a -> a
maximum :: forall a. Ord a => FirstToFinish m a -> a
$cminimum :: forall (m :: * -> *) a.
(Foldable m, Ord a) =>
FirstToFinish m a -> a
minimum :: forall a. Ord a => FirstToFinish m a -> a
$csum :: forall (m :: * -> *) a.
(Foldable m, Num a) =>
FirstToFinish m a -> a
sum :: forall a. Num a => FirstToFinish m a -> a
$cproduct :: forall (m :: * -> *) a.
(Foldable m, Num a) =>
FirstToFinish m a -> a
product :: forall a. Num a => FirstToFinish m a -> a
Foldable      via (Alt m)
  deriving (forall a' a. (a' -> a) -> FirstToFinish m a -> FirstToFinish m a')
-> (forall b a. b -> FirstToFinish m b -> FirstToFinish m a)
-> Contravariant (FirstToFinish m)
forall b a. b -> FirstToFinish m b -> FirstToFinish m a
forall a' a. (a' -> a) -> FirstToFinish m a -> FirstToFinish m a'
forall (m :: * -> *) b a.
Contravariant m =>
b -> FirstToFinish m b -> FirstToFinish m a
forall (m :: * -> *) a' a.
Contravariant m =>
(a' -> a) -> FirstToFinish m a -> FirstToFinish m a'
forall (f :: * -> *).
(forall a' a. (a' -> a) -> f a -> f a')
-> (forall b a. b -> f b -> f a) -> Contravariant f
$ccontramap :: forall (m :: * -> *) a' a.
Contravariant m =>
(a' -> a) -> FirstToFinish m a -> FirstToFinish m a'
contramap :: forall a' a. (a' -> a) -> FirstToFinish m a -> FirstToFinish m a'
$c>$ :: forall (m :: * -> *) b a.
Contravariant m =>
b -> FirstToFinish m b -> FirstToFinish m a
>$ :: forall b a. b -> FirstToFinish m b -> FirstToFinish m a
Contravariant via (Alt m)


-- | Last-to-finish synchronisation.  It is the multiplicative semigroup of
-- the [near-semiring](https://www.wikiwand.com/en/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'
--
newtype LastToFinish m a = LastToFinish { forall (m :: * -> *) a. LastToFinish m a -> m a
runLastToFinish :: m a }
  deriving newtype (forall a b. (a -> b) -> LastToFinish m a -> LastToFinish m b)
-> (forall a b. a -> LastToFinish m b -> LastToFinish m a)
-> Functor (LastToFinish m)
forall a b. a -> LastToFinish m b -> LastToFinish m a
forall a b. (a -> b) -> LastToFinish m a -> LastToFinish m b
forall (m :: * -> *) a b.
Functor m =>
a -> LastToFinish m b -> LastToFinish m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> LastToFinish m a -> LastToFinish m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> LastToFinish m a -> LastToFinish m b
fmap :: forall a b. (a -> b) -> LastToFinish m a -> LastToFinish m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> LastToFinish m b -> LastToFinish m a
<$ :: forall a b. a -> LastToFinish m b -> LastToFinish m a
Functor
  deriving         ( (forall x. LastToFinish m a -> Rep (LastToFinish m a) x)
-> (forall x. Rep (LastToFinish m a) x -> LastToFinish m a)
-> Generic (LastToFinish m a)
forall x. Rep (LastToFinish m a) x -> LastToFinish m a
forall x. LastToFinish m a -> Rep (LastToFinish m a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: * -> *) a x.
Rep (LastToFinish m a) x -> LastToFinish m a
forall (m :: * -> *) a x.
LastToFinish m a -> Rep (LastToFinish m a) x
$cfrom :: forall (m :: * -> *) a x.
LastToFinish m a -> Rep (LastToFinish m a) x
from :: forall x. LastToFinish m a -> Rep (LastToFinish m a) x
$cto :: forall (m :: * -> *) a x.
Rep (LastToFinish m a) x -> LastToFinish m a
to :: forall x. Rep (LastToFinish m a) x -> LastToFinish m a
Generic
                   , (forall a. LastToFinish m a -> Rep1 (LastToFinish m) a)
-> (forall a. Rep1 (LastToFinish m) a -> LastToFinish m a)
-> Generic1 (LastToFinish m)
forall a. Rep1 (LastToFinish m) a -> LastToFinish m a
forall a. LastToFinish m a -> Rep1 (LastToFinish m) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
forall (m :: * -> *) a. Rep1 (LastToFinish m) a -> LastToFinish m a
forall (m :: * -> *) a. LastToFinish m a -> Rep1 (LastToFinish m) a
$cfrom1 :: forall (m :: * -> *) a. LastToFinish m a -> Rep1 (LastToFinish m) a
from1 :: forall a. LastToFinish m a -> Rep1 (LastToFinish m) a
$cto1 :: forall (m :: * -> *) a. Rep1 (LastToFinish m) a -> LastToFinish m a
to1 :: forall a. Rep1 (LastToFinish m) a -> LastToFinish m a
Generic1
                   , Functor (LastToFinish m)
Functor (LastToFinish m) =>
(forall a. a -> LastToFinish m a)
-> (forall a b.
    LastToFinish m (a -> b) -> LastToFinish m a -> LastToFinish m b)
-> (forall a b c.
    (a -> b -> c)
    -> LastToFinish m a -> LastToFinish m b -> LastToFinish m c)
-> (forall a b.
    LastToFinish m a -> LastToFinish m b -> LastToFinish m b)
-> (forall a b.
    LastToFinish m a -> LastToFinish m b -> LastToFinish m a)
-> Applicative (LastToFinish m)
forall a. a -> LastToFinish m a
forall a b.
LastToFinish m a -> LastToFinish m b -> LastToFinish m a
forall a b.
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
forall a b.
LastToFinish m (a -> b) -> LastToFinish m a -> LastToFinish m b
forall a b c.
(a -> b -> c)
-> LastToFinish m a -> LastToFinish m b -> LastToFinish m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (LastToFinish m)
forall (m :: * -> *) a. Applicative m => a -> LastToFinish m a
forall (m :: * -> *) a b.
Applicative m =>
LastToFinish m a -> LastToFinish m b -> LastToFinish m a
forall (m :: * -> *) a b.
Applicative m =>
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
forall (m :: * -> *) a b.
Applicative m =>
LastToFinish m (a -> b) -> LastToFinish m a -> LastToFinish m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> LastToFinish m a -> LastToFinish m b -> LastToFinish m c
$cpure :: forall (m :: * -> *) a. Applicative m => a -> LastToFinish m a
pure :: forall a. a -> LastToFinish m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
LastToFinish m (a -> b) -> LastToFinish m a -> LastToFinish m b
<*> :: forall a b.
LastToFinish m (a -> b) -> LastToFinish m a -> LastToFinish m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> LastToFinish m a -> LastToFinish m b -> LastToFinish m c
liftA2 :: forall a b c.
(a -> b -> c)
-> LastToFinish m a -> LastToFinish m b -> LastToFinish m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
*> :: forall a b.
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
LastToFinish m a -> LastToFinish m b -> LastToFinish m a
<* :: forall a b.
LastToFinish m a -> LastToFinish m b -> LastToFinish m a
Applicative
                   , Applicative (LastToFinish m)
Applicative (LastToFinish m) =>
(forall a. LastToFinish m a)
-> (forall a.
    LastToFinish m a -> LastToFinish m a -> LastToFinish m a)
-> (forall a. LastToFinish m a -> LastToFinish m [a])
-> (forall a. LastToFinish m a -> LastToFinish m [a])
-> Alternative (LastToFinish m)
forall a. LastToFinish m a
forall a. LastToFinish m a -> LastToFinish m [a]
forall a. LastToFinish m a -> LastToFinish m a -> LastToFinish m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *). Alternative m => Applicative (LastToFinish m)
forall (m :: * -> *) a. Alternative m => LastToFinish m a
forall (m :: * -> *) a.
Alternative m =>
LastToFinish m a -> LastToFinish m [a]
forall (m :: * -> *) a.
Alternative m =>
LastToFinish m a -> LastToFinish m a -> LastToFinish m a
$cempty :: forall (m :: * -> *) a. Alternative m => LastToFinish m a
empty :: forall a. LastToFinish m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
LastToFinish m a -> LastToFinish m a -> LastToFinish m a
<|> :: forall a. LastToFinish m a -> LastToFinish m a -> LastToFinish m a
$csome :: forall (m :: * -> *) a.
Alternative m =>
LastToFinish m a -> LastToFinish m [a]
some :: forall a. LastToFinish m a -> LastToFinish m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
LastToFinish m a -> LastToFinish m [a]
many :: forall a. LastToFinish m a -> LastToFinish m [a]
Alternative
                   , Applicative (LastToFinish m)
Applicative (LastToFinish m) =>
(forall a b.
 LastToFinish m a -> (a -> LastToFinish m b) -> LastToFinish m b)
-> (forall a b.
    LastToFinish m a -> LastToFinish m b -> LastToFinish m b)
-> (forall a. a -> LastToFinish m a)
-> Monad (LastToFinish m)
forall a. a -> LastToFinish m a
forall a b.
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
forall a b.
LastToFinish m a -> (a -> LastToFinish m b) -> LastToFinish m b
forall (m :: * -> *). Monad m => Applicative (LastToFinish m)
forall (m :: * -> *) a. Monad m => a -> LastToFinish m a
forall (m :: * -> *) a b.
Monad m =>
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
forall (m :: * -> *) a b.
Monad m =>
LastToFinish m a -> (a -> LastToFinish m b) -> LastToFinish m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
LastToFinish m a -> (a -> LastToFinish m b) -> LastToFinish m b
>>= :: forall a b.
LastToFinish m a -> (a -> LastToFinish m b) -> LastToFinish m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
>> :: forall a b.
LastToFinish m a -> LastToFinish m b -> LastToFinish m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> LastToFinish m a
return :: forall a. a -> LastToFinish m a
Monad
                   , Monad (LastToFinish m)
Alternative (LastToFinish m)
(Alternative (LastToFinish m), Monad (LastToFinish m)) =>
(forall a. LastToFinish m a)
-> (forall a.
    LastToFinish m a -> LastToFinish m a -> LastToFinish m a)
-> MonadPlus (LastToFinish m)
forall a. LastToFinish m a
forall a. LastToFinish m a -> LastToFinish m a -> LastToFinish m a
forall (m :: * -> *). MonadPlus m => Monad (LastToFinish m)
forall (m :: * -> *). MonadPlus m => Alternative (LastToFinish m)
forall (m :: * -> *) a. MonadPlus m => LastToFinish m a
forall (m :: * -> *) a.
MonadPlus m =>
LastToFinish m a -> LastToFinish m a -> LastToFinish m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall (m :: * -> *) a. MonadPlus m => LastToFinish m a
mzero :: forall a. LastToFinish m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
LastToFinish m a -> LastToFinish m a -> LastToFinish m a
mplus :: forall a. LastToFinish m a -> LastToFinish m a -> LastToFinish m a
MonadPlus
                   , Functor (LastToFinish m)
Foldable (LastToFinish m)
(Functor (LastToFinish m), Foldable (LastToFinish m)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> LastToFinish m a -> f (LastToFinish m b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    LastToFinish m (f a) -> f (LastToFinish m a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> LastToFinish m a -> m (LastToFinish m b))
-> (forall (m :: * -> *) a.
    Monad m =>
    LastToFinish m (m a) -> m (LastToFinish m a))
-> Traversable (LastToFinish m)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *). Traversable m => Functor (LastToFinish m)
forall (m :: * -> *). Traversable m => Foldable (LastToFinish m)
forall (m :: * -> *) (m :: * -> *) a.
(Traversable m, Monad m) =>
LastToFinish m (m a) -> m (LastToFinish m a)
forall (m :: * -> *) (f :: * -> *) a.
(Traversable m, Applicative f) =>
LastToFinish m (f a) -> f (LastToFinish m a)
forall (m :: * -> *) (m :: * -> *) a b.
(Traversable m, Monad m) =>
(a -> m b) -> LastToFinish m a -> m (LastToFinish m b)
forall (m :: * -> *) (f :: * -> *) a b.
(Traversable m, Applicative f) =>
(a -> f b) -> LastToFinish m a -> f (LastToFinish m b)
forall (m :: * -> *) a.
Monad m =>
LastToFinish m (m a) -> m (LastToFinish m a)
forall (f :: * -> *) a.
Applicative f =>
LastToFinish m (f a) -> f (LastToFinish m a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LastToFinish m a -> m (LastToFinish m b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LastToFinish m a -> f (LastToFinish m b)
$ctraverse :: forall (m :: * -> *) (f :: * -> *) a b.
(Traversable m, Applicative f) =>
(a -> f b) -> LastToFinish m a -> f (LastToFinish m b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LastToFinish m a -> f (LastToFinish m b)
$csequenceA :: forall (m :: * -> *) (f :: * -> *) a.
(Traversable m, Applicative f) =>
LastToFinish m (f a) -> f (LastToFinish m a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
LastToFinish m (f a) -> f (LastToFinish m a)
$cmapM :: forall (m :: * -> *) (m :: * -> *) a b.
(Traversable m, Monad m) =>
(a -> m b) -> LastToFinish m a -> m (LastToFinish m b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LastToFinish m a -> m (LastToFinish m b)
$csequence :: forall (m :: * -> *) (m :: * -> *) a.
(Traversable m, Monad m) =>
LastToFinish m (m a) -> m (LastToFinish m a)
sequence :: forall (m :: * -> *) a.
Monad m =>
LastToFinish m (m a) -> m (LastToFinish m a)
Traversable
                   )
  deriving (forall m. Monoid m => LastToFinish m m -> m)
-> (forall m a. Monoid m => (a -> m) -> LastToFinish m a -> m)
-> (forall m a. Monoid m => (a -> m) -> LastToFinish m a -> m)
-> (forall a b. (a -> b -> b) -> b -> LastToFinish m a -> b)
-> (forall a b. (a -> b -> b) -> b -> LastToFinish m a -> b)
-> (forall b a. (b -> a -> b) -> b -> LastToFinish m a -> b)
-> (forall b a. (b -> a -> b) -> b -> LastToFinish m a -> b)
-> (forall a. (a -> a -> a) -> LastToFinish m a -> a)
-> (forall a. (a -> a -> a) -> LastToFinish m a -> a)
-> (forall a. LastToFinish m a -> [a])
-> (forall a. LastToFinish m a -> Bool)
-> (forall a. LastToFinish m a -> Int)
-> (forall a. Eq a => a -> LastToFinish m a -> Bool)
-> (forall a. Ord a => LastToFinish m a -> a)
-> (forall a. Ord a => LastToFinish m a -> a)
-> (forall a. Num a => LastToFinish m a -> a)
-> (forall a. Num a => LastToFinish m a -> a)
-> Foldable (LastToFinish m)
forall a. Eq a => a -> LastToFinish m a -> Bool
forall a. Num a => LastToFinish m a -> a
forall a. Ord a => LastToFinish m a -> a
forall m. Monoid m => LastToFinish m m -> m
forall a. LastToFinish m a -> Bool
forall a. LastToFinish m a -> Int
forall a. LastToFinish m a -> [a]
forall a. (a -> a -> a) -> LastToFinish m a -> a
forall m a. Monoid m => (a -> m) -> LastToFinish m a -> m
forall b a. (b -> a -> b) -> b -> LastToFinish m a -> b
forall a b. (a -> b -> b) -> b -> LastToFinish m a -> b
forall (m :: * -> *) a.
(Foldable m, Eq a) =>
a -> LastToFinish m a -> Bool
forall (m :: * -> *) a.
(Foldable m, Num a) =>
LastToFinish m a -> a
forall (m :: * -> *) a.
(Foldable m, Ord a) =>
LastToFinish m a -> a
forall (m :: * -> *) m.
(Foldable m, Monoid m) =>
LastToFinish m m -> m
forall (m :: * -> *) a. Foldable m => LastToFinish m a -> Bool
forall (m :: * -> *) a. Foldable m => LastToFinish m a -> Int
forall (m :: * -> *) a. Foldable m => LastToFinish m a -> [a]
forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> LastToFinish m a -> a
forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> LastToFinish m a -> m
forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> LastToFinish m a -> b
forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> LastToFinish m a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (m :: * -> *) m.
(Foldable m, Monoid m) =>
LastToFinish m m -> m
fold :: forall m. Monoid m => LastToFinish m m -> m
$cfoldMap :: forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> LastToFinish m a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> LastToFinish m a -> m
$cfoldMap' :: forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> LastToFinish m a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> LastToFinish m a -> m
$cfoldr :: forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> LastToFinish m a -> b
foldr :: forall a b. (a -> b -> b) -> b -> LastToFinish m a -> b
$cfoldr' :: forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> LastToFinish m a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> LastToFinish m a -> b
$cfoldl :: forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> LastToFinish m a -> b
foldl :: forall b a. (b -> a -> b) -> b -> LastToFinish m a -> b
$cfoldl' :: forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> LastToFinish m a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> LastToFinish m a -> b
$cfoldr1 :: forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> LastToFinish m a -> a
foldr1 :: forall a. (a -> a -> a) -> LastToFinish m a -> a
$cfoldl1 :: forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> LastToFinish m a -> a
foldl1 :: forall a. (a -> a -> a) -> LastToFinish m a -> a
$ctoList :: forall (m :: * -> *) a. Foldable m => LastToFinish m a -> [a]
toList :: forall a. LastToFinish m a -> [a]
$cnull :: forall (m :: * -> *) a. Foldable m => LastToFinish m a -> Bool
null :: forall a. LastToFinish m a -> Bool
$clength :: forall (m :: * -> *) a. Foldable m => LastToFinish m a -> Int
length :: forall a. LastToFinish m a -> Int
$celem :: forall (m :: * -> *) a.
(Foldable m, Eq a) =>
a -> LastToFinish m a -> Bool
elem :: forall a. Eq a => a -> LastToFinish m a -> Bool
$cmaximum :: forall (m :: * -> *) a.
(Foldable m, Ord a) =>
LastToFinish m a -> a
maximum :: forall a. Ord a => LastToFinish m a -> a
$cminimum :: forall (m :: * -> *) a.
(Foldable m, Ord a) =>
LastToFinish m a -> a
minimum :: forall a. Ord a => LastToFinish m a -> a
$csum :: forall (m :: * -> *) a.
(Foldable m, Num a) =>
LastToFinish m a -> a
sum :: forall a. Num a => LastToFinish m a -> a
$cproduct :: forall (m :: * -> *) a.
(Foldable m, Num a) =>
LastToFinish m a -> a
product :: forall a. Num a => LastToFinish m a -> a
Foldable via (Ap m)

instance MonadPlus m => Semigroup (LastToFinish m a) where
    LastToFinish m a
left <> :: LastToFinish m a -> LastToFinish m a -> LastToFinish m a
<> LastToFinish m a
right = m a -> LastToFinish m a
forall (m :: * -> *) a. m a -> LastToFinish m a
LastToFinish (m a -> LastToFinish m a) -> m a -> LastToFinish m a
forall a b. (a -> b) -> a -> b
$ do
      a <-  a -> Either a a
forall a b. a -> Either a b
Left  (a -> Either a a) -> m a -> m (Either a a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
left
        m (Either a a) -> m (Either a a) -> m (Either a a)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> Either a a
forall a b. b -> Either a b
Right (a -> Either a a) -> m a -> m (Either a a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
right
      case a of
        Left  {} -> m a
right
        Right {} -> m a
left

firstToLast :: FirstToFinish m a -> LastToFinish m a
firstToLast :: forall (m :: * -> *) a. FirstToFinish m a -> LastToFinish m a
firstToLast = FirstToFinish m a -> LastToFinish m a
forall a b. Coercible a b => a -> b
coerce

lastToFirst :: LastToFinish m a -> FirstToFinish m a
lastToFirst :: forall (m :: * -> *) a. LastToFinish m a -> FirstToFinish m a
lastToFirst = LastToFinish m a -> FirstToFinish m a
forall a b. Coercible a b => a -> b
coerce


-- | 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)
--
newtype LastToFinishM m a = LastToFinishM { forall (m :: * -> *) a. LastToFinishM m a -> m a
runLastToFinishM :: m a }
  deriving newtype (forall a b. (a -> b) -> LastToFinishM m a -> LastToFinishM m b)
-> (forall a b. a -> LastToFinishM m b -> LastToFinishM m a)
-> Functor (LastToFinishM m)
forall a b. a -> LastToFinishM m b -> LastToFinishM m a
forall a b. (a -> b) -> LastToFinishM m a -> LastToFinishM m b
forall (m :: * -> *) a b.
Functor m =>
a -> LastToFinishM m b -> LastToFinishM m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> LastToFinishM m a -> LastToFinishM m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> LastToFinishM m a -> LastToFinishM m b
fmap :: forall a b. (a -> b) -> LastToFinishM m a -> LastToFinishM m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> LastToFinishM m b -> LastToFinishM m a
<$ :: forall a b. a -> LastToFinishM m b -> LastToFinishM m a
Functor
  deriving         ( (forall x. LastToFinishM m a -> Rep (LastToFinishM m a) x)
-> (forall x. Rep (LastToFinishM m a) x -> LastToFinishM m a)
-> Generic (LastToFinishM m a)
forall x. Rep (LastToFinishM m a) x -> LastToFinishM m a
forall x. LastToFinishM m a -> Rep (LastToFinishM m a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: * -> *) a x.
Rep (LastToFinishM m a) x -> LastToFinishM m a
forall (m :: * -> *) a x.
LastToFinishM m a -> Rep (LastToFinishM m a) x
$cfrom :: forall (m :: * -> *) a x.
LastToFinishM m a -> Rep (LastToFinishM m a) x
from :: forall x. LastToFinishM m a -> Rep (LastToFinishM m a) x
$cto :: forall (m :: * -> *) a x.
Rep (LastToFinishM m a) x -> LastToFinishM m a
to :: forall x. Rep (LastToFinishM m a) x -> LastToFinishM m a
Generic
                   , (forall a. LastToFinishM m a -> Rep1 (LastToFinishM m) a)
-> (forall a. Rep1 (LastToFinishM m) a -> LastToFinishM m a)
-> Generic1 (LastToFinishM m)
forall a. Rep1 (LastToFinishM m) a -> LastToFinishM m a
forall a. LastToFinishM m a -> Rep1 (LastToFinishM m) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
forall (m :: * -> *) a.
Rep1 (LastToFinishM m) a -> LastToFinishM m a
forall (m :: * -> *) a.
LastToFinishM m a -> Rep1 (LastToFinishM m) a
$cfrom1 :: forall (m :: * -> *) a.
LastToFinishM m a -> Rep1 (LastToFinishM m) a
from1 :: forall a. LastToFinishM m a -> Rep1 (LastToFinishM m) a
$cto1 :: forall (m :: * -> *) a.
Rep1 (LastToFinishM m) a -> LastToFinishM m a
to1 :: forall a. Rep1 (LastToFinishM m) a -> LastToFinishM m a
Generic1
                   , Functor (LastToFinishM m)
Functor (LastToFinishM m) =>
(forall a. a -> LastToFinishM m a)
-> (forall a b.
    LastToFinishM m (a -> b) -> LastToFinishM m a -> LastToFinishM m b)
-> (forall a b c.
    (a -> b -> c)
    -> LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m c)
-> (forall a b.
    LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b)
-> (forall a b.
    LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m a)
-> Applicative (LastToFinishM m)
forall a. a -> LastToFinishM m a
forall a b.
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m a
forall a b.
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
forall a b.
LastToFinishM m (a -> b) -> LastToFinishM m a -> LastToFinishM m b
forall a b c.
(a -> b -> c)
-> LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (LastToFinishM m)
forall (m :: * -> *) a. Applicative m => a -> LastToFinishM m a
forall (m :: * -> *) a b.
Applicative m =>
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m a
forall (m :: * -> *) a b.
Applicative m =>
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
forall (m :: * -> *) a b.
Applicative m =>
LastToFinishM m (a -> b) -> LastToFinishM m a -> LastToFinishM m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m c
$cpure :: forall (m :: * -> *) a. Applicative m => a -> LastToFinishM m a
pure :: forall a. a -> LastToFinishM m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
LastToFinishM m (a -> b) -> LastToFinishM m a -> LastToFinishM m b
<*> :: forall a b.
LastToFinishM m (a -> b) -> LastToFinishM m a -> LastToFinishM m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m c
liftA2 :: forall a b c.
(a -> b -> c)
-> LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
*> :: forall a b.
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m a
<* :: forall a b.
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m a
Applicative
                   , Applicative (LastToFinishM m)
Applicative (LastToFinishM m) =>
(forall a. LastToFinishM m a)
-> (forall a.
    LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a)
-> (forall a. LastToFinishM m a -> LastToFinishM m [a])
-> (forall a. LastToFinishM m a -> LastToFinishM m [a])
-> Alternative (LastToFinishM m)
forall a. LastToFinishM m a
forall a. LastToFinishM m a -> LastToFinishM m [a]
forall a.
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *).
Alternative m =>
Applicative (LastToFinishM m)
forall (m :: * -> *) a. Alternative m => LastToFinishM m a
forall (m :: * -> *) a.
Alternative m =>
LastToFinishM m a -> LastToFinishM m [a]
forall (m :: * -> *) a.
Alternative m =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
$cempty :: forall (m :: * -> *) a. Alternative m => LastToFinishM m a
empty :: forall a. LastToFinishM m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
<|> :: forall a.
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
$csome :: forall (m :: * -> *) a.
Alternative m =>
LastToFinishM m a -> LastToFinishM m [a]
some :: forall a. LastToFinishM m a -> LastToFinishM m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
LastToFinishM m a -> LastToFinishM m [a]
many :: forall a. LastToFinishM m a -> LastToFinishM m [a]
Alternative
                   , Applicative (LastToFinishM m)
Applicative (LastToFinishM m) =>
(forall a b.
 LastToFinishM m a -> (a -> LastToFinishM m b) -> LastToFinishM m b)
-> (forall a b.
    LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b)
-> (forall a. a -> LastToFinishM m a)
-> Monad (LastToFinishM m)
forall a. a -> LastToFinishM m a
forall a b.
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
forall a b.
LastToFinishM m a -> (a -> LastToFinishM m b) -> LastToFinishM m b
forall (m :: * -> *). Monad m => Applicative (LastToFinishM m)
forall (m :: * -> *) a. Monad m => a -> LastToFinishM m a
forall (m :: * -> *) a b.
Monad m =>
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
forall (m :: * -> *) a b.
Monad m =>
LastToFinishM m a -> (a -> LastToFinishM m b) -> LastToFinishM m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
LastToFinishM m a -> (a -> LastToFinishM m b) -> LastToFinishM m b
>>= :: forall a b.
LastToFinishM m a -> (a -> LastToFinishM m b) -> LastToFinishM m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
>> :: forall a b.
LastToFinishM m a -> LastToFinishM m b -> LastToFinishM m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> LastToFinishM m a
return :: forall a. a -> LastToFinishM m a
Monad
                   , Monad (LastToFinishM m)
Alternative (LastToFinishM m)
(Alternative (LastToFinishM m), Monad (LastToFinishM m)) =>
(forall a. LastToFinishM m a)
-> (forall a.
    LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a)
-> MonadPlus (LastToFinishM m)
forall a. LastToFinishM m a
forall a.
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
forall (m :: * -> *). MonadPlus m => Monad (LastToFinishM m)
forall (m :: * -> *). MonadPlus m => Alternative (LastToFinishM m)
forall (m :: * -> *) a. MonadPlus m => LastToFinishM m a
forall (m :: * -> *) a.
MonadPlus m =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall (m :: * -> *) a. MonadPlus m => LastToFinishM m a
mzero :: forall a. LastToFinishM m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
mplus :: forall a.
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
MonadPlus
                   , Functor (LastToFinishM m)
Foldable (LastToFinishM m)
(Functor (LastToFinishM m), Foldable (LastToFinishM m)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> LastToFinishM m a -> f (LastToFinishM m b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    LastToFinishM m (f a) -> f (LastToFinishM m a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> LastToFinishM m a -> m (LastToFinishM m b))
-> (forall (m :: * -> *) a.
    Monad m =>
    LastToFinishM m (m a) -> m (LastToFinishM m a))
-> Traversable (LastToFinishM m)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *). Traversable m => Functor (LastToFinishM m)
forall (m :: * -> *). Traversable m => Foldable (LastToFinishM m)
forall (m :: * -> *) (m :: * -> *) a.
(Traversable m, Monad m) =>
LastToFinishM m (m a) -> m (LastToFinishM m a)
forall (m :: * -> *) (f :: * -> *) a.
(Traversable m, Applicative f) =>
LastToFinishM m (f a) -> f (LastToFinishM m a)
forall (m :: * -> *) (m :: * -> *) a b.
(Traversable m, Monad m) =>
(a -> m b) -> LastToFinishM m a -> m (LastToFinishM m b)
forall (m :: * -> *) (f :: * -> *) a b.
(Traversable m, Applicative f) =>
(a -> f b) -> LastToFinishM m a -> f (LastToFinishM m b)
forall (m :: * -> *) a.
Monad m =>
LastToFinishM m (m a) -> m (LastToFinishM m a)
forall (f :: * -> *) a.
Applicative f =>
LastToFinishM m (f a) -> f (LastToFinishM m a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LastToFinishM m a -> m (LastToFinishM m b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LastToFinishM m a -> f (LastToFinishM m b)
$ctraverse :: forall (m :: * -> *) (f :: * -> *) a b.
(Traversable m, Applicative f) =>
(a -> f b) -> LastToFinishM m a -> f (LastToFinishM m b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LastToFinishM m a -> f (LastToFinishM m b)
$csequenceA :: forall (m :: * -> *) (f :: * -> *) a.
(Traversable m, Applicative f) =>
LastToFinishM m (f a) -> f (LastToFinishM m a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
LastToFinishM m (f a) -> f (LastToFinishM m a)
$cmapM :: forall (m :: * -> *) (m :: * -> *) a b.
(Traversable m, Monad m) =>
(a -> m b) -> LastToFinishM m a -> m (LastToFinishM m b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LastToFinishM m a -> m (LastToFinishM m b)
$csequence :: forall (m :: * -> *) (m :: * -> *) a.
(Traversable m, Monad m) =>
LastToFinishM m (m a) -> m (LastToFinishM m a)
sequence :: forall (m :: * -> *) a.
Monad m =>
LastToFinishM m (m a) -> m (LastToFinishM m a)
Traversable
                   )
  deriving NonEmpty (LastToFinishM m a) -> LastToFinishM m a
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
(LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a)
-> (NonEmpty (LastToFinishM m a) -> LastToFinishM m a)
-> (forall b.
    Integral b =>
    b -> LastToFinishM m a -> LastToFinishM m a)
-> Semigroup (LastToFinishM m a)
forall b. Integral b => b -> LastToFinishM m a -> LastToFinishM m a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (m :: * -> *) a.
(Applicative m, Semigroup a) =>
NonEmpty (LastToFinishM m a) -> LastToFinishM m a
forall (m :: * -> *) a.
(Applicative m, Semigroup a) =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
forall (m :: * -> *) a b.
(Applicative m, Semigroup a, Integral b) =>
b -> LastToFinishM m a -> LastToFinishM m a
$c<> :: forall (m :: * -> *) a.
(Applicative m, Semigroup a) =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
<> :: LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
$csconcat :: forall (m :: * -> *) a.
(Applicative m, Semigroup a) =>
NonEmpty (LastToFinishM m a) -> LastToFinishM m a
sconcat :: NonEmpty (LastToFinishM m a) -> LastToFinishM m a
$cstimes :: forall (m :: * -> *) a b.
(Applicative m, Semigroup a, Integral b) =>
b -> LastToFinishM m a -> LastToFinishM m a
stimes :: forall b. Integral b => b -> LastToFinishM m a -> LastToFinishM m a
Semigroup via (Ap m a)
  deriving Semigroup (LastToFinishM m a)
LastToFinishM m a
Semigroup (LastToFinishM m a) =>
LastToFinishM m a
-> (LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a)
-> ([LastToFinishM m a] -> LastToFinishM m a)
-> Monoid (LastToFinishM m a)
[LastToFinishM m a] -> LastToFinishM m a
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
Semigroup (LastToFinishM m a)
forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
LastToFinishM m a
forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
[LastToFinishM m a] -> LastToFinishM m a
forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
$cmempty :: forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
LastToFinishM m a
mempty :: LastToFinishM m a
$cmappend :: forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
mappend :: LastToFinishM m a -> LastToFinishM m a -> LastToFinishM m a
$cmconcat :: forall (m :: * -> *) a.
(Applicative m, Monoid a) =>
[LastToFinishM m a] -> LastToFinishM m a
mconcat :: [LastToFinishM m a] -> LastToFinishM m a
Monoid    via (Ap m a)
  deriving (forall m. Monoid m => LastToFinishM m m -> m)
-> (forall m a. Monoid m => (a -> m) -> LastToFinishM m a -> m)
-> (forall m a. Monoid m => (a -> m) -> LastToFinishM m a -> m)
-> (forall a b. (a -> b -> b) -> b -> LastToFinishM m a -> b)
-> (forall a b. (a -> b -> b) -> b -> LastToFinishM m a -> b)
-> (forall b a. (b -> a -> b) -> b -> LastToFinishM m a -> b)
-> (forall b a. (b -> a -> b) -> b -> LastToFinishM m a -> b)
-> (forall a. (a -> a -> a) -> LastToFinishM m a -> a)
-> (forall a. (a -> a -> a) -> LastToFinishM m a -> a)
-> (forall a. LastToFinishM m a -> [a])
-> (forall a. LastToFinishM m a -> Bool)
-> (forall a. LastToFinishM m a -> Int)
-> (forall a. Eq a => a -> LastToFinishM m a -> Bool)
-> (forall a. Ord a => LastToFinishM m a -> a)
-> (forall a. Ord a => LastToFinishM m a -> a)
-> (forall a. Num a => LastToFinishM m a -> a)
-> (forall a. Num a => LastToFinishM m a -> a)
-> Foldable (LastToFinishM m)
forall a. Eq a => a -> LastToFinishM m a -> Bool
forall a. Num a => LastToFinishM m a -> a
forall a. Ord a => LastToFinishM m a -> a
forall m. Monoid m => LastToFinishM m m -> m
forall a. LastToFinishM m a -> Bool
forall a. LastToFinishM m a -> Int
forall a. LastToFinishM m a -> [a]
forall a. (a -> a -> a) -> LastToFinishM m a -> a
forall m a. Monoid m => (a -> m) -> LastToFinishM m a -> m
forall b a. (b -> a -> b) -> b -> LastToFinishM m a -> b
forall a b. (a -> b -> b) -> b -> LastToFinishM m a -> b
forall (m :: * -> *) a.
(Foldable m, Eq a) =>
a -> LastToFinishM m a -> Bool
forall (m :: * -> *) a.
(Foldable m, Num a) =>
LastToFinishM m a -> a
forall (m :: * -> *) a.
(Foldable m, Ord a) =>
LastToFinishM m a -> a
forall (m :: * -> *) m.
(Foldable m, Monoid m) =>
LastToFinishM m m -> m
forall (m :: * -> *) a. Foldable m => LastToFinishM m a -> Bool
forall (m :: * -> *) a. Foldable m => LastToFinishM m a -> Int
forall (m :: * -> *) a. Foldable m => LastToFinishM m a -> [a]
forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> LastToFinishM m a -> a
forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> LastToFinishM m a -> m
forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> LastToFinishM m a -> b
forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> LastToFinishM m a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (m :: * -> *) m.
(Foldable m, Monoid m) =>
LastToFinishM m m -> m
fold :: forall m. Monoid m => LastToFinishM m m -> m
$cfoldMap :: forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> LastToFinishM m a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> LastToFinishM m a -> m
$cfoldMap' :: forall (m :: * -> *) m a.
(Foldable m, Monoid m) =>
(a -> m) -> LastToFinishM m a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> LastToFinishM m a -> m
$cfoldr :: forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> LastToFinishM m a -> b
foldr :: forall a b. (a -> b -> b) -> b -> LastToFinishM m a -> b
$cfoldr' :: forall (m :: * -> *) a b.
Foldable m =>
(a -> b -> b) -> b -> LastToFinishM m a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> LastToFinishM m a -> b
$cfoldl :: forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> LastToFinishM m a -> b
foldl :: forall b a. (b -> a -> b) -> b -> LastToFinishM m a -> b
$cfoldl' :: forall (m :: * -> *) b a.
Foldable m =>
(b -> a -> b) -> b -> LastToFinishM m a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> LastToFinishM m a -> b
$cfoldr1 :: forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> LastToFinishM m a -> a
foldr1 :: forall a. (a -> a -> a) -> LastToFinishM m a -> a
$cfoldl1 :: forall (m :: * -> *) a.
Foldable m =>
(a -> a -> a) -> LastToFinishM m a -> a
foldl1 :: forall a. (a -> a -> a) -> LastToFinishM m a -> a
$ctoList :: forall (m :: * -> *) a. Foldable m => LastToFinishM m a -> [a]
toList :: forall a. LastToFinishM m a -> [a]
$cnull :: forall (m :: * -> *) a. Foldable m => LastToFinishM m a -> Bool
null :: forall a. LastToFinishM m a -> Bool
$clength :: forall (m :: * -> *) a. Foldable m => LastToFinishM m a -> Int
length :: forall a. LastToFinishM m a -> Int
$celem :: forall (m :: * -> *) a.
(Foldable m, Eq a) =>
a -> LastToFinishM m a -> Bool
elem :: forall a. Eq a => a -> LastToFinishM m a -> Bool
$cmaximum :: forall (m :: * -> *) a.
(Foldable m, Ord a) =>
LastToFinishM m a -> a
maximum :: forall a. Ord a => LastToFinishM m a -> a
$cminimum :: forall (m :: * -> *) a.
(Foldable m, Ord a) =>
LastToFinishM m a -> a
minimum :: forall a. Ord a => LastToFinishM m a -> a
$csum :: forall (m :: * -> *) a.
(Foldable m, Num a) =>
LastToFinishM m a -> a
sum :: forall a. Num a => LastToFinishM m a -> a
$cproduct :: forall (m :: * -> *) a.
(Foldable m, Num a) =>
LastToFinishM m a -> a
product :: forall a. Num a => LastToFinishM m a -> a
Foldable  via (Ap m)

firstToLastM :: FirstToFinish m a -> LastToFinishM m a
firstToLastM :: forall (m :: * -> *) a. FirstToFinish m a -> LastToFinishM m a
firstToLastM = FirstToFinish m a -> LastToFinishM m a
forall a b. Coercible a b => a -> b
coerce

lastToFirstM :: LastToFinishM m a -> FirstToFinish m a
lastToFirstM :: forall (m :: * -> *) a. LastToFinishM m a -> FirstToFinish m a
lastToFirstM = LastToFinishM m a -> FirstToFinish m a
forall a b. Coercible a b => a -> b
coerce