Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data State s (m :: * -> *) k
- get :: (Member (State s) sig, Carrier sig m) => m s
- gets :: (Member (State s) sig, Carrier sig m, Functor m) => (s -> a) -> m a
- put :: (Member (State s) sig, Carrier sig m) => s -> m ()
- modify :: (Member (State s) sig, Carrier sig m, Monad m) => (s -> s) -> m ()
- runState :: (Carrier sig m, Effect sig) => s -> Eff (StateC s m) a -> m (s, a)
- evalState :: (Carrier sig m, Effect sig, Functor m) => s -> Eff (StateC s m) a -> m a
- execState :: (Carrier sig m, Effect sig, Functor m) => s -> Eff (StateC s m) a -> m s
- newtype StateC s m a = StateC {
- runStateC :: s -> m (s, a)
Documentation
get :: (Member (State s) sig, Carrier sig m) => m s Source #
Get the current state value.
snd (run (runState a get)) == a
gets :: (Member (State s) sig, Carrier sig m, Functor m) => (s -> a) -> m a Source #
Project a function out of the current state value.
snd (run (runState a (gets (applyFun f)))) == applyFun f a
put :: (Member (State s) sig, Carrier sig m) => s -> m () Source #
Replace the state value with a new value.
fst (run (runState a (put b))) == b
snd (run (runState a (get <* put b))) == a
snd (run (runState a (put b *> get))) == b
modify :: (Member (State s) sig, Carrier sig m, Monad m) => (s -> s) -> m () Source #
Replace the state value with the result of applying a function to the current state value.
This is strict in the new state; if you need laziness, use get >>= put . f
.
fst (run (runState a (modify (+1)))) == (1 + a :: Integer)
runState :: (Carrier sig m, Effect sig) => s -> Eff (StateC s m) a -> m (s, a) Source #
Run a State
effect starting from the passed value.
run (runState a (pure b)) == (a, b)
evalState :: (Carrier sig m, Effect sig, Functor m) => s -> Eff (StateC s m) a -> m a Source #
Run a State
effect, yielding the result value and discarding the final state.
run (evalState a (pure b)) == b