mirror of
https://github.com/composewell/streamly.git
synced 2024-10-26 19:50:19 +03:00
Add withReaderT to Stream
This commit is contained in:
parent
ef07f20410
commit
37a6fc1e6b
@ -17,8 +17,12 @@ module Streamly.Internal.Data.Stream.Transformer
|
||||
|
||||
-- * Inner Monad Operations
|
||||
, liftInner
|
||||
|
||||
, runReaderT
|
||||
, usingReaderT
|
||||
, withReaderT
|
||||
, localReaderT
|
||||
|
||||
, evalStateT
|
||||
, runStateT
|
||||
, usingStateT
|
||||
@ -130,6 +134,28 @@ usingReaderT
|
||||
-> Stream m a
|
||||
usingReaderT r f xs = runReaderT r $ f $ liftInner xs
|
||||
|
||||
-- | Modify the environment of the underlying ReaderT monad.
|
||||
{-# INLINABLE withReaderT #-}
|
||||
withReaderT :: Monad m =>
|
||||
(r2 -> r1) -> Stream (ReaderT r1 m) a -> Stream (ReaderT r2 m) a
|
||||
withReaderT f (Stream step state) = Stream step1 state
|
||||
|
||||
where
|
||||
|
||||
{-# INLINE_LATE step1 #-}
|
||||
step1 gst st = do
|
||||
r <- Reader.withReaderT f (step (adaptState gst) st)
|
||||
return $ case r of
|
||||
Yield x s -> Yield x s
|
||||
Skip s -> Skip s
|
||||
Stop -> Stop
|
||||
|
||||
-- | Modify the environment of the underlying ReaderT monad.
|
||||
{-# INLINABLE localReaderT #-}
|
||||
localReaderT :: Monad m =>
|
||||
(r -> r) -> Stream (ReaderT r m) a -> Stream (ReaderT r m) a
|
||||
localReaderT = withReaderT
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Sharing read write state in a stream
|
||||
------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user