module Data.Bifunctor.Join
( Join(..)
) where
import Control.Applicative
import Data.Biapplicative
import Data.Bifoldable
import Data.Bifunctor.Apply
import Data.Bitraversable
import Data.Foldable
import Data.Functor.Bind
import Data.Semigroup.Bifoldable
import Data.Semigroup.Bitraversable
import Data.Semigroup.Foldable
import Data.Semigroup.Traversable
import Data.Traversable
newtype Join p a = Join { runJoin :: p a a }
deriving instance Eq (p a a) => Eq (Join p a)
deriving instance Ord (p a a) => Ord (Join p a)
deriving instance Show (p a a) => Show (Join p a)
deriving instance Read (p a a) => Read (Join p a)
instance Bifunctor p => Functor (Join p) where
fmap f (Join a) = Join (bimap f f a)
instance Biapplicative p => Applicative (Join p) where
pure a = Join (bipure a a)
Join f <*> Join a = Join (f <<*>> a)
Join a *> Join b = Join (a *>> b)
Join a <* Join b = Join (a <<* b)
instance Biapply p => Apply (Join p) where
Join f <.> Join a = Join (f <<.>> a)
Join a .> Join b = Join (a .>> b)
Join a <. Join b = Join (a <<. b)
instance Bifoldable p => Foldable (Join p) where
foldMap f (Join a) = bifoldMap f f a
instance Bitraversable p => Traversable (Join p) where
traverse f (Join a) = fmap Join (bitraverse f f a)
sequenceA (Join a) = fmap Join (bisequenceA a)
instance Bifoldable1 p => Foldable1 (Join p) where
foldMap1 f (Join a) = bifoldMap1 f f a
instance Bitraversable1 p => Traversable1 (Join p) where
traverse1 f (Join a) = fmap Join (bitraverse1 f f a)
sequence1 (Join a) = fmap Join (bisequence1 a)