Tee is a newtype wrapper over the Fold type providing distributing
Applicative, Semigroup, Monoid, Num, Floating and Fractional
instances.
The input received by the composed Tee is replicated and distributed to the constituent folds of the Tee.
For example, to compute the average of numbers in a stream without going through the stream twice:
avg = (/) <$> (Tee Fold.sum) <*> (Tee $ fmap fromIntegral Fold.length)Stream.fold (unTee avg) $ Stream.fromList [1.0..100.0]50.5
Similarly, the Semigroup and Monoid instances of Tee distribute the input to both the folds and combine the outputs using Monoid or Semigroup instances of the output types:
import Data.Monoid (Sum(..))t = Tee Fold.one <> Tee Fold.latestStream.fold (unTee t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)Just (Sum {getSum = 101.0})
The Num, Floating, and Fractional instances work in the same way.
Instances7Functor, Applicative, Floating, Fractional, Num, Semigroup, …
Functor m => Functor (Tee m a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.TeeMonad m => Applicative (Tee m a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.Tee(Monad m, Floating b) => Floating (Tee m a b)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.Tee(Monad m, Fractional b) => Fractional (Tee m a b)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.TeeBinary Fractional operations distribute the input to both the argument Tees and combine their outputs using the Fractional instance of the output type.
(Monad m, Num b) => Num (Tee m a b)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.Tee(Semigroup b, Monad m) => Semigroup (Tee m a b)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.Tee(Monoid b, Monad m) => Monoid (Tee m a b)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Fold.Tee