2-- Module : Streamly.Internal.Data.Fold.Tee
3-- Copyright : (c) 2020 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
9-- A newtype wrapper over the 'Fold' type providing distributing 'Applicative',
10-- 'Semigroup', 'Monoid', 'Num', 'Floating' and 'Fractional' instances.
12module Streamly.Internal.Data.Fold.Tee
17import Control.Applicative (liftA2)
18#if __GLASGOW_HASKELL__ < 808
19import Data.Semigroup (Semigroup(..))
21import Streamly.Internal.Data.Fold.Type (Fold)
23import qualified Streamly.Internal.Data.Fold.Type as Fold
25-- | @Tee@ is a newtype wrapper over the 'Fold' type providing distributing
26-- 'Applicative', 'Semigroup', 'Monoid', 'Num', 'Floating' and 'Fractional'
31 Tee { toFold :: Fold m a b }
34-- | '<*>' distributes the input to both the argument 'Tee's and combines their
35-- outputs using function application.
37instance Monad m => Applicative (Tee m a) where
40 pure a = Tee (Fold.fromPure a)
43 (<*>) a b = Tee (Fold.teeWith ($) (toFold a) (toFold b))
45-- | '<>' distributes the input to both the argument 'Tee's and combines their
46-- outputs using the 'Semigroup' instance of the output type.
48instance (Semigroup b, Monad m) => Semigroup (Tee m a b) where
52-- | '<>' distributes the input to both the argument 'Tee's and combines their
53-- outputs using the 'Monoid' instance of the output type.
55instance (Semigroup b, Monoid b, Monad m) => Monoid (Tee m a b) where
59 {-# INLINE mappend #-}
62-- | Binary 'Num' operations distribute the input to both the argument 'Tee's
63-- and combine their outputs using the 'Num' instance of the output type.
65instance (Monad m, Num b) => Num (Tee m a b) where
66 {-# INLINE fromInteger #-}
67 fromInteger = pure . fromInteger
87-- | Binary 'Fractional' operations distribute the input to both the argument
88-- 'Tee's and combine their outputs using the 'Fractional' instance of the
91instance (Monad m, Fractional b) => Fractional (Tee m a b) where
92 {-# INLINE fromRational #-}
93 fromRational = pure . fromRational
101-- | Binary 'Floating' operations distribute the input to both the argument
102-- 'Tee's and combine their outputs using the 'Floating' instance of the output
104instance (Monad m, Floating b) => Floating (Tee m a b) where
156 {-# INLINE logBase #-}
157 logBase = liftA2 logBase
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