on master help sign in
Cleanup unfold exception combinator exports
42b0ab9Harendra Kumar
src/Streamly/Data/Unfold.hs+4−4
@@ -106,12 +106,12 @@ module Streamly.Data.Unfold
106 -- ** Nesting
106 -- ** Nesting
107 , many
107 , many
108
108
109− -- ** Exceptions
109+ -- ** Resource Management
110− , before
111− , after
112− , onException
113 , finally
110 , finally
114 , bracket
111 , bracket
112+
113+ -- ** Exceptions
114+ , onException
115 , handle
115 , handle
116 )
116 )
117where
117where
src/Streamly/Internal/Data/Unfold.hs+8−25
@@ -985,37 +985,20 @@ gbracket bef exc aft (Unfold estep einject) (Unfold step1 inject1) =
985 Skip s -> return $ Skip (Left s)
985 Skip s -> return $ Skip (Left s)
986 Stop -> return Stop
986 Stop -> return Stop
987
987
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−
997-- | Run a side effect @a -> m c@ on the input @a@ before unfolding it using
988-- | Run a side effect @a -> m c@ on the input @a@ before unfolding it using
998-- @Unfold m a b@.
989-- @Unfold m a b@.
999--
990--
991+-- > before f = lmapM (\a -> f a >> return a)
992+--
1000-- /Pre-release/
993-- /Pre-release/
1001{-# INLINE_NORMAL before #-}
994{-# INLINE_NORMAL before #-}
1002−before :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
995+before :: (a -> m c) -> Unfold m a b -> Unfold m a b
1003−before action (Unfold step1 inject1) = Unfold step inject
996+before action (Unfold step inject) = Unfold step (action >> 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
1018
997
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+--
1019{-# INLINE_NORMAL _after #-}
1002{-# INLINE_NORMAL _after #-}
1020_after :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
1003_after :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
1021_after aft = gbracket_ return (fmap Right) aft undefined
1004_after aft = gbracket_ return (fmap Right) aft undefined