@@ -985,37 +985,20 @@ gbracket bef exc aft (Unfold estep einject) (Unfold step1 inject1) =
985985 Skip s -> return $ Skip (Left s)
986986 Stop -> return Stop
987987
988−-- The custom implementation of "before" is slightly faster (5-7%) than
989−-- "_before". This is just to document and make sure that we can always use
990−-- gbracket to implement before. The same applies to other combinators as well.
991−--
992−{-# INLINE_NORMAL _before #-}
993−_before :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
994−_before action = gbracket_ (\x -> action x >> return x) (fmap Right)
995− (\_ -> return ()) undefined
996−
997988-- | Run a side effect @a -> m c@ on the input @a@ before unfolding it using
998989-- @Unfold m a b@.
999990--
991+-- > before f = lmapM (\a -> f a >> return a)
992+--
1000993-- /Pre-release/
1001994{-# INLINE_NORMAL before #-}
1002−before :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
1003−before action (Unfold step1 inject1) = Unfold step inject
1004−
1005− where
1006−
1007− inject x = do
1008− _ <- action x
1009− inject1 x
1010−
1011− {-# INLINE_LATE step #-}
1012− step st = do
1013− res <- step1 st
1014− case res of
1015− Yield x s -> return $ Yield x s
1016− Skip s -> return $ Skip s
1017− Stop -> return Stop
995+before :: (a -> m c) -> Unfold m a b -> Unfold m a b
996+before action (Unfold step inject) = Unfold step (action >> inject)
1018997
998+-- The custom implementation of "after_" is slightly faster (5-7%) than
999+-- "_after". This is just to document and make sure that we can always use
1000+-- gbracket to implement after_ The same applies to other combinators as well.
1001+--
10191002{-# INLINE_NORMAL _after #-}
10201003_after :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
10211004_after aft = gbracket_ return (fmap Right) aft undefined