Add Control.Monad.Freer.State.gets

This commit is contained in:
Martin Huschenbett 2018-01-27 11:01:17 +01:00
parent 888465fd06
commit 9aa407f674

View File

@ -27,6 +27,7 @@ module Control.Monad.Freer.State
, get
, put
, modify
, gets
-- * State Handlers
, runState
@ -61,6 +62,11 @@ put s = send (Put s)
modify :: forall s effs. Member (State s) effs => (s -> s) -> Eff effs ()
modify f = fmap f get >>= put
-- | Retrieve a specific component of the current state using the provided
-- projection function.
gets :: forall s a effs. Member (State s) effs => (s -> a) -> Eff effs a
gets f = f <$> get
-- | Handler for 'State' effects.
runState :: forall s effs a. s -> Eff (State s ': effs) a -> Eff effs (a, s)
runState s0 = handleRelayS s0 (\s x -> pure (x, s)) $ \s x k -> case x of