mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 19:47:10 +03:00
Add localReaderT to StreamK
This commit is contained in:
parent
76fc41fefd
commit
358e82cb32
@ -13,13 +13,16 @@ module Streamly.Internal.Data.StreamK.Transformer
|
||||
|
||||
, liftInner
|
||||
, evalStateT
|
||||
|
||||
, localReaderT
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad.Trans.Class (MonadTrans(lift))
|
||||
import Control.Monad.Trans.State.Strict (StateT)
|
||||
import Streamly.Internal.Data.StreamK.Type
|
||||
(StreamK, nil, cons, uncons, concatEffect)
|
||||
(StreamK(..), nil, cons, uncons, concatEffect, foldStream, mkStream)
|
||||
import Control.Monad.Trans.Reader (ReaderT, local)
|
||||
|
||||
import qualified Control.Monad.Trans.State.Strict as State
|
||||
|
||||
@ -77,3 +80,12 @@ liftInner = go
|
||||
case res of
|
||||
Just (h, t) -> cons h (go t)
|
||||
Nothing -> nil
|
||||
|
||||
-- | Modify the environment of the underlying ReaderT monad.
|
||||
{-# INLINABLE localReaderT #-}
|
||||
localReaderT :: (r -> r) -> StreamK (ReaderT r m) a -> StreamK (ReaderT r m) a
|
||||
localReaderT f m =
|
||||
mkStream $ \st yld sng stp ->
|
||||
let single = local f . sng
|
||||
yieldk a r = local f $ yld a (localReaderT f r)
|
||||
in foldStream st yieldk single (local f stp) m
|
||||
|
Loading…
Reference in New Issue
Block a user