@@ -57,9 +57,11 @@ module Streamly.Internal.Data.Fold
57 , rollingHashFirstN
57 , rollingHashFirstN
58 -- , rollingHashLastN
58 -- , rollingHashLastN
60+ -- ** Fold Semigroups
60 -- ** Full Folds (Monoidal)
63 -- ** Full Folds (Monoidal)
64 , foldMapM
66 , foldMapM
@@ -610,18 +612,15 @@ rollingHashFirstN n = ltake n rollingHash
610-- Monoidal left folds
612-- Monoidal left folds
611------------------------------------------------------------------------------
613------------------------------------------------------------------------------
613−-- | 'mappend' the elements of an input stream to a provided starting value.
615+-- | Append the elements of an input stream to a provided starting value.
615−-- > S.fold (FL.mconcatTo 10) (S.map Sum $ S.enumerateFromTo 1 10)
617−-- This could be faster than (fmap (m0 <>) FL.mconcat) especially when we have
617+-- > S.fold (FL.sconcat 10) (S.map Sum $ S.enumerateFromTo 1 10)
618−-- to perform the operation many times.
620-- /Internal/
619-- /Internal/
622−{-# INLINE mconcatTo #-}
621+{-# INLINE sconcat #-}
623−mconcatTo :: (Monad m, Monoid a) => a -> Fold m a a
622+sconcat :: (Monad m, Semigroup a) => a -> Fold m a a
624−mconcatTo i = Fold (\x a -> return $ mappend x a) (return i) return
623+sconcat i = Fold (\x a -> return $ x <> a) (return i) return
626-- | Fold an input stream consisting of monoidal elements using 'mappend'
625-- | Fold an input stream consisting of monoidal elements using 'mappend'
627-- and 'mempty'.
626-- and 'mempty'.
@@ -631,7 +630,7 @@ mconcatTo i = Fold (\x a -> return $ mappend x a) (return i) return
631-- @since 0.7.0
630-- @since 0.7.0
632{-# INLINE mconcat #-}
631{-# INLINE mconcat #-}
633mconcat :: (Monad m, Monoid a) => Fold m a a
632mconcat :: (Monad m, Monoid a) => Fold m a a
634−mconcat = mconcatTo mempty
633+mconcat = sconcat mempty
637-- > foldMap f = lmap f mconcat
636-- > foldMap f = lmap f mconcat