@@ -132,6 +132,7 @@ module Streamly.Internal.Data.Fold
132 , scanMany
132 , scanMany
133 , postscan
133 , postscan
134 , indexed
134 , indexed
136 -- ** Zipping Input
137 -- ** Zipping Input
137 , zipWithM
138 , zipWithM
@@ -291,6 +292,7 @@ where
291#include "inline.hs"
292#include "inline.hs"
292#include "ArrayMacros.h"
293#include "ArrayMacros.h"
295+import Control.Monad (void)
294import Control.Monad.IO.Class (MonadIO(..))
296import Control.Monad.IO.Class (MonadIO(..))
295import Data.Bifunctor (first)
297import Data.Bifunctor (first)
296import Data.Bits (shiftL, shiftR, (.|.), (.&.))
298import Data.Bits (shiftL, shiftR, (.|.), (.&.))
@@ -401,6 +403,18 @@ mapMaybe f = lmap f . filter isJust . lmap fromJust
401-- Transformations on fold inputs
403-- Transformations on fold inputs
402------------------------------------------------------------------------------
404------------------------------------------------------------------------------
406+-- | Apply a monadic function to each element flowing through and discard the
409+-- >>> Stream.fold (Fold.trace print Fold.drain) $ (Stream.enumerateFromTo (1 :: Int) 2)
415+trace :: Monad m => (a -> m b) -> Fold m a r -> Fold m a r
416+trace f = lmapM (\x -> void (f x) >> return x)
404-- rename to lpipe?
418-- rename to lpipe?
406-- | Apply a transformation on a 'Fold' using a 'Pipe'.
420-- | Apply a transformation on a 'Fold' using a 'Pipe'.