effectful-core-2.3.1.0: An easy to use, performant extensible effects library.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Effectful.State.Dynamic

Description

The dynamically dispatched variant of the State effect.

Note: unless you plan to change interpretations at runtime, it's recommended to use one of the statically dispatched variants, i.e. Effectful.State.Static.Local or Effectful.State.Static.Shared.

Synopsis

Effect

data State s :: Effect where Source #

Provide access to a mutable value of type s.

Constructors

Get :: State s m s 
Put :: s -> State s m () 
State :: (s -> (a, s)) -> State s m a 
StateM :: (s -> m (a, s)) -> State s m a 

Instances

Instances details
type DispatchOf (State s) Source # 
Instance details

Defined in Effectful.State.Dynamic

Handlers

Local

runStateLocal :: s -> Eff (State s : es) a -> Eff es (a, s) Source #

Run the State effect with the given initial state and return the final value along with the final state (via Effectful.State.Static.Local).

evalStateLocal :: s -> Eff (State s : es) a -> Eff es a Source #

Run the State effect with the given initial state and return the final value, discarding the final state (via Effectful.State.Static.Local).

execStateLocal :: s -> Eff (State s : es) a -> Eff es s Source #

Run the State effect with the given initial state and return the final state, discarding the final value (via Effectful.State.Static.Local).

Shared

runStateShared :: s -> Eff (State s : es) a -> Eff es (a, s) Source #

Run the State effect with the given initial state and return the final value along with the final state (via Effectful.State.Static.Shared).

evalStateShared :: s -> Eff (State s : es) a -> Eff es a Source #

Run the State effect with the given initial state and return the final value, discarding the final state (via Effectful.State.Static.Shared).

execStateShared :: s -> Eff (State s : es) a -> Eff es s Source #

Run the State effect with the given initial state and return the final state, discarding the final value (via Effectful.State.Static.Shared).

Operations

get :: (HasCallStack, State s :> es) => Eff es s Source #

Fetch the current value of the state.

gets :: (HasCallStack, State s :> es) => (s -> a) -> Eff es a Source #

Get a function of the current state.

gets f ≡ f <$> get

put :: (HasCallStack, State s :> es) => s -> Eff es () Source #

Set the current state to the given value.

state :: (HasCallStack, State s :> es) => (s -> (a, s)) -> Eff es a Source #

Apply the function to the current state and return a value.

modify :: (HasCallStack, State s :> es) => (s -> s) -> Eff es () Source #

Apply the function to the current state.

modify f ≡ state (\s -> ((), f s))

stateM :: (HasCallStack, State s :> es) => (s -> Eff es (a, s)) -> Eff es a Source #

Apply the monadic function to the current state and return a value.

modifyM :: (HasCallStack, State s :> es) => (s -> Eff es s) -> Eff es () Source #

Apply the monadic function to the current state.

modifyM f ≡ stateM (\s -> ((), ) <$> f s)