effectful-core
Safe HaskellSafe-Inferred
LanguageGHC2021

Effectful.Labeled.State

Description

Convenience functions for the Labeled State effect.

Since: 2.4.0.0

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

Deprecated: Use a combination of Get and Put instead.

Instances

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

Defined in Effectful.Internal.Effect.Dynamic

Handlers

Local

runStateLocal Source #

Arguments

:: forall label s es a. HasCallStack 
=> s

The initial state.

-> Eff (Labeled label (State s) : es) a 
-> Eff es (a, s) 

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 Source #

Arguments

:: forall label s es a. HasCallStack 
=> s

The initial state.

-> Eff (Labeled label (State s) : es) a 
-> Eff es a 

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

execStateLocal Source #

Arguments

:: forall label s es a. HasCallStack 
=> s

The initial state.

-> Eff (Labeled label (State s) : es) a 
-> Eff es s 

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 Source #

Arguments

:: forall label s es a. HasCallStack 
=> s

The initial state.

-> Eff (Labeled label (State s) : es) a 
-> Eff es (a, s) 

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 Source #

Arguments

:: forall label s es a. HasCallStack 
=> s

The initial state.

-> Eff (Labeled label (State s) : es) a 
-> Eff es a 

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

execStateShared Source #

Arguments

:: forall label s es a. HasCallStack 
=> s

The initial state.

-> Eff (Labeled label (State s) : es) a 
-> Eff es s 

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 :: forall label s es. (HasCallStack, Labeled label (State s) :> es) => Eff es s Source #

Fetch the current value of the state.

gets Source #

Arguments

:: forall label s es a. (HasCallStack, Labeled label (State s) :> es) 
=> (s -> a)

.

-> Eff es a 

Get a function of the current state.

gets f ≡ f <$> get

put Source #

Arguments

:: forall label s es. (HasCallStack, Labeled label (State s) :> es) 
=> s

.

-> Eff es () 

Set the current state to the given value.

state Source #

Arguments

:: forall label s es a. (HasCallStack, Labeled label (State s) :> es) 
=> (s -> (a, s))

.

-> Eff es a 

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

modify Source #

Arguments

:: forall label s es. (HasCallStack, Labeled label (State s) :> es) 
=> (s -> s)

.

-> Eff es () 

Apply the function to the current state.

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

stateM Source #

Arguments

:: forall label s es a. (HasCallStack, Labeled label (State s) :> es) 
=> (s -> Eff es (a, s))

.

-> Eff es a 

Deprecated: Use a combination of get and put instead.

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

modifyM Source #

Arguments

:: forall label s es. (HasCallStack, Labeled label (State s) :> es) 
=> (s -> Eff es s)

.

-> Eff es () 

Deprecated: Use a combination of get and put instead.

Apply the monadic function to the current state.

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

Re-exports

newtype Labeled (label :: k) (e :: Effect) :: Effect where Source #

Assign a label to an effect.

Note: labeled effects are best used together with the effectful-plugin package, as it significantly improves their usability.

The constructor is for sending labeled operations of a dynamically dispatched effect to the handler:

>>> import Effectful.Dispatch.Dynamic
>>> :{
  data X :: Effect where
    X :: X m Int
  type instance DispatchOf X = Dynamic
:}
>>> :{
  runPureEff . runLabeled @"x" (interpret_ $ \X -> pure 333) $ do
    send $ Labeled @"x" X
:}
333

Constructors

Labeled :: forall label e m a. e m a -> Labeled label e m a

Since: 2.4.0.0

Instances

Instances details
type DispatchOf (Labeled label e) Source # 
Instance details

Defined in Effectful.Labeled

type DispatchOf (Labeled label e) = DispatchOf e
data StaticRep (Labeled label e) Source # 
Instance details

Defined in Effectful.Labeled

data StaticRep (Labeled label e)