module Control.Effect.Reader
(
Ask(..)
, Local(..)
, Reader
, ask
, asks
, local
, runAskConst
, runAskAction
, askToAsk
, runReader
, runAskConstSimple
, runAskActionSimple
, askToAskSimple
, ReaderThreads
, ReaderC
) where
import Control.Effect
import Control.Effect.Internal.Reader
import Control.Monad.Trans.Reader (ReaderT(..))
ask :: Eff (Ask i) m => m i
ask :: m i
ask = Ask i m i -> m i
forall (e :: Effect) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send Ask i m i
forall i (m :: * -> *). Ask i m i
Ask
{-# INLINE ask #-}
asks :: Eff (Ask i) m => (i -> a) -> m a
asks :: (i -> a) -> m a
asks = ((i -> a) -> m i -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m i
forall i (m :: * -> *). Eff (Ask i) m => m i
ask)
{-# INLINE asks #-}
local :: Eff (Local i) m => (i -> i) -> m a -> m a
local :: (i -> i) -> m a -> m a
local i -> i
f m a
m = Local i m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send ((i -> i) -> m a -> Local i m a
forall i (m :: * -> *) a. (i -> i) -> m a -> Local i m a
Local i -> i
f m a
m)
{-# INLINE local #-}
runReader :: forall i m a p
. ( Carrier m
, Threaders '[ReaderThreads] m p
)
=> i
-> ReaderC i m a
-> m a
runReader :: i -> ReaderC i m a -> m a
runReader i
i ReaderC i m a
m = ReaderT i m a -> i -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (ReaderC i m a -> ReaderT i m a
forall i (m :: * -> *) a. ReaderC i m a -> ReaderT i m a
unReaderC ReaderC i m a
m) i
i
{-# INLINE runReader #-}
runAskConst :: forall i m a
. Carrier m
=> i
-> InterpretReifiedC (Ask i) m a
-> m a
runAskConst :: i -> InterpretReifiedC (Ask i) m a -> m a
runAskConst i
i = EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(RepresentationalEff e, Carrier m) =>
EffHandler e m -> InterpretReifiedC e m a -> m a
interpret (EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a)
-> EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
Ask i (Effly z) x
Ask -> i -> Effly z i
forall (m :: * -> *) a. Monad m => a -> m a
return i
i
{-# INLINE runAskConst #-}
runAskAction :: forall i m a
. Carrier m
=> m i
-> InterpretReifiedC (Ask i) m a
-> m a
runAskAction :: m i -> InterpretReifiedC (Ask i) m a -> m a
runAskAction m i
m = EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(RepresentationalEff e, Carrier m) =>
EffHandler e m -> InterpretReifiedC e m a -> m a
interpret (EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a)
-> EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
Ask i (Effly z) x
Ask -> m i -> Effly z i
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase m i
m
{-# INLINE runAskAction #-}
askToAsk :: forall i j m a
. Eff (Ask j) m
=> (j -> i)
-> InterpretReifiedC (Ask i) m a
-> m a
askToAsk :: (j -> i) -> InterpretReifiedC (Ask i) m a -> m a
askToAsk j -> i
f = EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(RepresentationalEff e, Carrier m) =>
EffHandler e m -> InterpretReifiedC e m a -> m a
interpret (EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a)
-> EffHandler (Ask i) m -> InterpretReifiedC (Ask i) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
Ask i (Effly z) x
Ask -> (j -> i) -> Effly z i
forall i (m :: * -> *) a. Eff (Ask i) m => (i -> a) -> m a
asks j -> i
f
{-# INLINE askToAsk #-}
runAskConstSimple :: forall i m a p
. ( Carrier m
, Threaders '[ReaderThreads] m p
)
=> i
-> InterpretSimpleC (Ask i) m a
-> m a
runAskConstSimple :: i -> InterpretSimpleC (Ask i) m a -> m a
runAskConstSimple i
i = EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a
forall (e :: Effect) (m :: * -> *) a (p :: [Effect]).
(RepresentationalEff e, Threaders '[ReaderThreads] m p,
Carrier m) =>
EffHandler e m -> InterpretSimpleC e m a -> m a
interpretSimple (EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a)
-> EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
Ask i (Effly z) x
Ask -> i -> Effly z i
forall (m :: * -> *) a. Monad m => a -> m a
return i
i
{-# INLINE runAskConstSimple #-}
runAskActionSimple :: forall i m a p
. ( Carrier m
, Threaders '[ReaderThreads] m p
)
=> m i
-> InterpretSimpleC (Ask i) m a
-> m a
runAskActionSimple :: m i -> InterpretSimpleC (Ask i) m a -> m a
runAskActionSimple m i
mi = EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a
forall (e :: Effect) (m :: * -> *) a (p :: [Effect]).
(RepresentationalEff e, Threaders '[ReaderThreads] m p,
Carrier m) =>
EffHandler e m -> InterpretSimpleC e m a -> m a
interpretSimple (EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a)
-> EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
Ask i (Effly z) x
Ask -> m i -> Effly z i
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase m i
mi
{-# INLINE runAskActionSimple #-}
askToAskSimple :: forall i j m a p
. ( Eff (Ask j) m
, Threaders '[ReaderThreads] m p
)
=> (j -> i)
-> InterpretSimpleC (Ask i) m a
-> m a
askToAskSimple :: (j -> i) -> InterpretSimpleC (Ask i) m a -> m a
askToAskSimple j -> i
f = EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a
forall (e :: Effect) (m :: * -> *) a (p :: [Effect]).
(RepresentationalEff e, Threaders '[ReaderThreads] m p,
Carrier m) =>
EffHandler e m -> InterpretSimpleC e m a -> m a
interpretSimple (EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a)
-> EffHandler (Ask i) m -> InterpretSimpleC (Ask i) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
Ask i (Effly z) x
Ask -> (j -> i) -> Effly z i
forall i (m :: * -> *) a. Eff (Ask i) m => (i -> a) -> m a
asks j -> i
f
{-# INLINE askToAskSimple #-}