2-- Module : Streamly.Data.Fold.Tee
3-- Copyright : (c) 2021 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
9-- The 'Tee' type is a newtype wrapper over the 'Streamly.Data.Fold.Fold' type providing
10-- distributive 'Applicative', 'Semigroup', 'Monoid', 'Num', 'Floating' and
11-- 'Fractional' instances. The input received by the composed 'Tee' is
12-- replicated and distributed to both the constituent Tees.
14-- For example, to compute the average of numbers in a stream without going
15-- through the stream twice:
17-- >>> import Streamly.Data.Fold.Tee (Tee(..))
18-- >>> import qualified Streamly.Prelude as Stream
19-- >>> import qualified Streamly.Data.Fold as Fold
21-- >>> avg = (/) <$> (Tee Fold.sum) <*> (Tee $ fmap fromIntegral Fold.length)
22-- >>> Stream.fold (toFold avg) $ Stream.fromList [1.0..100.0]
25-- Similarly, the 'Semigroup' and 'Monoid' instances of 'Tee' distribute the
26-- input to both the folds and combine the outputs using Monoid or Semigroup
27-- instances of the output types:
29-- >>> import Data.Monoid (Sum(..))
30-- >>> t = Tee Fold.head <> Tee Fold.last
31-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
32-- Just (Sum {getSum = 101.0})
34-- The 'Num', 'Floating', and 'Fractional' instances work in the same way.
36module Streamly.Data.Fold.Tee
41import Streamly.Internal.Data.Fold.Tee
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list