@@ -14,10 +14,10 @@
1414-- For example, to compute the average of numbers in a stream without going
1515-- through the stream twice:
1616--
17−-- >>> import Streamly.Internal.Data.Fold.Tee (mkT, toFold)
17+-- >>> import Streamly.Internal.Data.Fold.Tee (Tee(..), toFold)
1818-- >>> import Streamly.Internal.Data.Fold as Fold
1919--
20−-- >>> avg = (/) <$> (mkT Fold.sum) <*> (mkT $ fmap fromIntegral Fold.length)
20+-- >>> avg = (/) <$> (Tee Fold.sum) <*> (Tee $ fmap fromIntegral Fold.length)
2121-- >>> Stream.fold (toFold avg) $ Stream.fromList [1.0..100.0]
2222-- 50.5
2323--
@@ -26,20 +26,18 @@
2626-- instances of the output types:
2727--
2828-- >>> import Data.Monoid (Sum(..))
29−-- >>> t = mkT Fold.head <> mkT Fold.last
29+-- >>> t = Tee Fold.head <> Tee Fold.last
3030-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
3131-- Just (Sum {getSum = 101.0})
3232--
3333-- The 'Num', 'Floating', and 'Fractional' instances work in the same way.
3434--
3535module Streamly.Internal.Data.Fold.Tee
36− ( Tee(..)
37− , mkT
36+ ( Tee(..)
3837 )
3938where
4039
4140import Control.Applicative (liftA2)
42−import Data.Coerce (coerce)
4341#if __GLASGOW_HASKELL__ < 808
4442import Data.Semigroup (Semigroup(..))
4543#endif
@@ -56,24 +54,16 @@ newtype Tee m a b =
5654 Tee { toFold :: Fold m a b }
5755 deriving (Functor)
5856
59−-- | Make a 'Tee' from a 'Fold'.
60−--
61−-- /Pre-release/
62−{-# INLINE mkT #-}
63−mkT :: Fold m a b -> Tee m a b
64−mkT = coerce
65−
66−
6757-- | '<*>' distributes the input to both the argument 'Tee's and combines their
6858-- outputs using function application.
6959--
7060instance Monad m => Applicative (Tee m a) where
7161
7262 {-# INLINE pure #-}
73− pure a = mkT (Fold.yield a)
63+ pure a = Tee (Fold.yield a)
7464
7565 {-# INLINE (<*>) #-}
76− (<*>) a b = mkT (Fold.teeWith ($) (toFold a) (toFold b))
66+ (<*>) a b = Tee (Fold.teeWith ($) (toFold a) (toFold b))
7767
7868-- | '<>' distributes the input to both the argument 'Tee's and combines their
7969-- outputs using the 'Semigroup' instance of the output type.