mirror of
https://github.com/lexi-lambda/freer-simple.git
synced 2024-09-11 08:05:51 +03:00
Add Control.Monad.Freer.State.gets
This commit is contained in:
parent
888465fd06
commit
9aa407f674
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user