File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919
2020 Generalise type signature of ` toList_ ` .
2121
22+ Add ` wrapEffect ` .
23+
2224- 0.2.1.0
2325
2426 Adding ` Semigroup ` instances for GHC 8.4.
Original file line number Diff line number Diff line change @@ -138,8 +138,8 @@ module Streaming.Prelude (
138138 , read
139139 , show
140140 , cons
141- , slidingWindow
142-
141+ , slidingWindow
142+ , wrapEffect
143143
144144 -- * Splitting and inspecting streams of elements
145145 , next
@@ -770,6 +770,19 @@ effects = loop where
770770 Step (_ :> rest) -> loop rest
771771{-# INLINABLE effects #-}
772772
773+ {-| Before evaluating the monadic action returning the next step in the 'Stream', @wrapEffect@
774+ extracts the value in a monadic computation @m a@ and passes it to a computation @a -> m y@.
775+
776+ -}
777+ wrapEffect :: (Monad m , Functor f ) => m a -> (a -> m y ) -> Stream f m r -> Stream f m r
778+ wrapEffect m f = loop where
779+ loop stream = do
780+ x <- lift m
781+ step <- lift $ inspect stream
782+ _ <- lift $ f x
783+ either pure loop' step
784+ loop' stream = wrap (fmap loop stream)
785+
773786{-| Exhaust a stream remembering only whether @a@ was an element.
774787
775788-}
You can’t perform that action at this time.
0 commit comments