@@ -132,6 +132,7 @@ module Streamly.Internal.Data.Fold
132132 , scanMany
133133 , postscan
134134 , indexed
135+ , trace
135136
136137 -- ** Zipping Input
137138 , zipWithM
@@ -291,6 +292,7 @@ where
291292#include "inline.hs"
292293#include "ArrayMacros.h"
293294
295+import Control.Monad (void)
294296import Control.Monad.IO.Class (MonadIO(..))
295297import Data.Bifunctor (first)
296298import Data.Bits (shiftL, shiftR, (.|.), (.&.))
@@ -401,6 +403,18 @@ mapMaybe f = lmap f . filter isJust . lmap fromJust
401403-- Transformations on fold inputs
402404------------------------------------------------------------------------------
403405
406+-- | Apply a monadic function to each element flowing through and discard the
407+-- results.
408+--
409+-- >>> Stream.fold (Fold.trace print Fold.drain) $ (Stream.enumerateFromTo (1 :: Int) 2)
410+-- 1
411+-- 2
412+--
413+-- /Pre-release/
414+{-# INLINE trace #-}
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)
417+
404418-- rename to lpipe?
405419--
406420-- | Apply a transformation on a 'Fold' using a 'Pipe'.