module Control.Effect.State
(
State(..)
, get
, gets
, put
, modify
, modifyLazy
, state
, Algebra
, Has
, run
) where
import Control.Algebra
import Control.Effect.State.Internal (State(..))
get :: Has (State s) sig m => m s
get :: forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
m s
get = forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send forall s (m :: * -> *). State s m s
Get
{-# INLINEABLE get #-}
gets :: Has (State s) sig m => (s -> a) -> m a
gets :: forall s (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (State s) sig m =>
(s -> a) -> m a
gets = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
m s
get)
{-# INLINEABLE gets #-}
put :: Has (State s) sig m => s -> m ()
put :: forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
s -> m ()
put s
s = forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (forall s (m :: * -> *). s -> State s m ()
Put s
s)
{-# INLINEABLE put #-}
modify :: Has (State s) sig m => (s -> s) -> m ()
modify :: forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
(s -> s) -> m ()
modify s -> s
f = do
s
a <- forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
m s
get
forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
s -> m ()
put forall a b. (a -> b) -> a -> b
$! s -> s
f s
a
{-# INLINEABLE modify #-}
modifyLazy :: Has (State s) sig m => (s -> s) -> m ()
modifyLazy :: forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
(s -> s) -> m ()
modifyLazy s -> s
f = forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
m s
get forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
s -> m ()
put forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> s
f
{-# INLINEABLE modifyLazy #-}
state :: Has (State s) sig m => (s -> (s, a)) -> m a
state :: forall s (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (State s) sig m =>
(s -> (s, a)) -> m a
state s -> (s, a)
f = do
(s
s', a
a) <- forall s (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (State s) sig m =>
(s -> a) -> m a
gets s -> (s, a)
f
a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (State s) sig m =>
s -> m ()
put s
s'
{-# INLINEABLE state #-}