{-# LANGUAGE Trustworthy #-}
module Relude.Monad.Trans
(
usingReader
, usingReaderT
, etaReaderT
, evaluatingState
, evaluatingStateT
, executingState
, executingStateT
, usingState
, usingStateT
, hoistMaybe
, hoistEither
) where
import GHC.Exts (oneShot)
import Relude.Applicative (Applicative (pure))
import Relude.Container.Reexport (fst, snd)
import Relude.Function (flip, (.))
import Relude.Functor (Functor, (<$>))
import Relude.Monad.Reexport (Either, ExceptT (..), Maybe, MaybeT (..), Reader, ReaderT (..), State,
StateT, runReader, runReaderT, runState, runStateT)
usingReaderT :: r -> ReaderT r m a -> m a
usingReaderT :: forall r (m :: * -> *) a. r -> ReaderT r m a -> m a
usingReaderT = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT
{-# INLINE usingReaderT #-}
usingReader :: r -> Reader r a -> a
usingReader :: forall r a. r -> Reader r a -> a
usingReader = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r a. Reader r a -> r -> a
runReader
{-# INLINE usingReader #-}
etaReaderT :: ReaderT r m a -> ReaderT r m a
etaReaderT :: forall r (m :: * -> *) a. ReaderT r m a -> ReaderT r m a
etaReaderT = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall b c a. (b -> c) -> (a -> b) -> a -> c
. oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT
{-# INLINE etaReaderT #-}
usingStateT :: s -> StateT s m a -> m (a, s)
usingStateT :: forall s (m :: * -> *) a. s -> StateT s m a -> m (a, s)
usingStateT = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT
{-# INLINE usingStateT #-}
usingState :: s -> State s a -> (a, s)
usingState :: forall s a. s -> State s a -> (a, s)
usingState = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall s a. State s a -> s -> (a, s)
runState
{-# INLINE usingState #-}
evaluatingStateT :: Functor f => s -> StateT s f a -> f a
evaluatingStateT :: forall (f :: * -> *) s a. Functor f => s -> StateT s f a -> f a
evaluatingStateT s
s StateT s f a
st = forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) a. s -> StateT s m a -> m (a, s)
usingStateT s
s StateT s f a
st
{-# INLINE evaluatingStateT #-}
evaluatingState :: s -> State s a -> a
evaluatingState :: forall s a. s -> State s a -> a
evaluatingState s
s State s a
st = forall a b. (a, b) -> a
fst (forall s a. s -> State s a -> (a, s)
usingState s
s State s a
st)
{-# INLINE evaluatingState #-}
executingStateT :: Functor f => s -> StateT s f a -> f s
executingStateT :: forall (f :: * -> *) s a. Functor f => s -> StateT s f a -> f s
executingStateT s
s StateT s f a
st = forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) a. s -> StateT s m a -> m (a, s)
usingStateT s
s StateT s f a
st
{-# INLINE executingStateT #-}
executingState :: s -> State s a -> s
executingState :: forall s a. s -> State s a -> s
executingState s
s State s a
st = forall a b. (a, b) -> b
snd (forall s a. s -> State s a -> (a, s)
usingState s
s State s a
st)
{-# INLINE executingState #-}
hoistMaybe :: Applicative m => Maybe a -> MaybeT m a
hoistMaybe :: forall (m :: * -> *) a. Applicative m => Maybe a -> MaybeT m a
hoistMaybe Maybe a
m = forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
m)
{-# INLINE hoistMaybe #-}
hoistEither :: Applicative m => Either e a -> ExceptT e m a
hoistEither :: forall (m :: * -> *) e a.
Applicative m =>
Either e a -> ExceptT e m a
hoistEither Either e a
e = forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (forall (f :: * -> *) a. Applicative f => a -> f a
pure Either e a
e)
{-# INLINE hoistEither #-}