@@ -13,7 +13,11 @@ module Streamly.Internal.Data.Fold.Tee
16+import Control.Applicative (liftA2)
16import Data.Coerce (coerce)
17import Data.Coerce (coerce)
18+#if __GLASGOW_HASKELL__ < 808
19+import Data.Semigroup (Semigroup(..))
17import Streamly.Internal.Data.Fold.Types (Fold)
21import Streamly.Internal.Data.Fold.Types (Fold)
19import qualified Streamly.Internal.Data.Fold.Types as Fold
23import qualified Streamly.Internal.Data.Fold.Types as Fold
@@ -49,3 +53,106 @@ instance Monad m => Applicative (Tee m a) where
50 {-# INLINE (<*>) #-}
54 {-# INLINE (<*>) #-}
51 (<*>) a b = fromFold (Fold.teeWith ($) (toFold a) (toFold b))
55 (<*>) a b = fromFold (Fold.teeWith ($) (toFold a) (toFold b))
57+-- | Combines the outputs (the type @b@) using their 'Semigroup' instances.
58+instance (Semigroup b, Monad m) => Semigroup (Tee m a b) where
62+-- | Combines the outputs (the type @b@) using their 'Monoid' instances.
63+instance (Semigroup b, Monoid b, Monad m) => Monoid (Tee m a b) where
64+ {-# INLINE mempty #-}
67+ {-# INLINE mappend #-}
70+-- | Combines the outputs (type @b@) using their 'Num' instances.
71+instance (Monad m, Num b) => Num (Tee m a b) where
72+ {-# INLINE fromInteger #-}
73+ fromInteger = pure . fromInteger
75+ {-# INLINE negate #-}
81+ {-# INLINE signum #-}
93+-- | Combines the outputs (type @b@) using their 'Fractional' instances.
94+instance (Monad m, Fractional b) => Fractional (Tee m a b) where
95+ {-# INLINE fromRational #-}
96+ fromRational = pure . fromRational
104+-- | Combines the outputs using their 'Floating' instances.
105+instance (Monad m, Floating b) => Floating (Tee m a b) where
145+ {-# INLINE asinh #-}
148+ {-# INLINE atanh #-}
151+ {-# INLINE acosh #-}
157+ {-# INLINE logBase #-}
158+ logBase = liftA2 logBase