on master help sign in
Remove mkT from Tee module
095409bRanjeet Kumar Ranjan
src/Streamly/Internal/Data/Fold/Tee.hs+6−16
@@ -14,10 +14,10 @@
14-- For example, to compute the average of numbers in a stream without going
14-- For example, to compute the average of numbers in a stream without going
15-- through the stream twice:
15-- through the stream twice:
16--
16--
17−-- >>> import Streamly.Internal.Data.Fold.Tee (mkT, toFold)
17+-- >>> import Streamly.Internal.Data.Fold.Tee (Tee(..), toFold)
18-- >>> import Streamly.Internal.Data.Fold as Fold
18-- >>> import Streamly.Internal.Data.Fold as Fold
19--
19--
20−-- >>> avg = (/) <$> (mkT Fold.sum) <*> (mkT $ fmap fromIntegral Fold.length)
20+-- >>> avg = (/) <$> (Tee Fold.sum) <*> (Tee $ fmap fromIntegral Fold.length)
21-- >>> Stream.fold (toFold avg) $ Stream.fromList [1.0..100.0]
21-- >>> Stream.fold (toFold avg) $ Stream.fromList [1.0..100.0]
22-- 50.5
22-- 50.5
23--
23--
@@ -26,20 +26,18 @@
26-- instances of the output types:
26-- instances of the output types:
27--
27--
28-- >>> import Data.Monoid (Sum(..))
28-- >>> import Data.Monoid (Sum(..))
29−-- >>> t = mkT Fold.head <> mkT Fold.last
29+-- >>> t = Tee Fold.head <> Tee Fold.last
30-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
30-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
31-- Just (Sum {getSum = 101.0})
31-- Just (Sum {getSum = 101.0})
32--
32--
33-- The 'Num', 'Floating', and 'Fractional' instances work in the same way.
33-- The 'Num', 'Floating', and 'Fractional' instances work in the same way.
34--
34--
35module Streamly.Internal.Data.Fold.Tee
35module Streamly.Internal.Data.Fold.Tee
36− ( Tee(..)
36+ ( Tee(..)
37− , mkT
38 )
37 )
39where
38where
40
39
41import Control.Applicative (liftA2)
40import Control.Applicative (liftA2)
42−import Data.Coerce (coerce)
43#if __GLASGOW_HASKELL__ < 808
41#if __GLASGOW_HASKELL__ < 808
44import Data.Semigroup (Semigroup(..))
42import Data.Semigroup (Semigroup(..))
45#endif
43#endif
@@ -56,24 +54,16 @@ newtype Tee m a b =
56 Tee { toFold :: Fold m a b }
54 Tee { toFold :: Fold m a b }
57 deriving (Functor)
55 deriving (Functor)
58
56
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−
67-- | '<*>' distributes the input to both the argument 'Tee's and combines their
57-- | '<*>' distributes the input to both the argument 'Tee's and combines their
68-- outputs using function application.
58-- outputs using function application.
69--
59--
70instance Monad m => Applicative (Tee m a) where
60instance Monad m => Applicative (Tee m a) where
71
61
72 {-# INLINE pure #-}
62 {-# INLINE pure #-}
73− pure a = mkT (Fold.yield a)
63+ pure a = Tee (Fold.yield a)
74
64
75 {-# INLINE (<*>) #-}
65 {-# INLINE (<*>) #-}
76− (<*>) a b = mkT (Fold.teeWith ($) (toFold a) (toFold b))
66+ (<*>) a b = Tee (Fold.teeWith ($) (toFold a) (toFold b))
77
67
78-- | '<>' distributes the input to both the argument 'Tee's and combines their
68-- | '<>' distributes the input to both the argument 'Tee's and combines their
79-- outputs using the 'Semigroup' instance of the output type.
69-- outputs using the 'Semigroup' instance of the output type.