Adds a mutable state of type σ to a monad.
Actions in the resulting monad are functions that take an initial state and return, in m, a tuple
of a value and a state.
Instances For
- Lake.instMonadDStoreStateTDRBMapOfMonadOfEqOfCmpWrt
 - Lake.instMonadLiftTStateTOfMonadOfMonadStateOf_lake
 - Lake.instMonadStoreNameStateTNameMapOfMonad
 - Lake.instMonadStoreStateTRBArrayOfMonad
 - Lake.instMonadStoreStateTRBMapOfMonad
 - Lean.instMonadAlwaysExceptStateT
 - MonadSatisfying.instStateT
 - Qq.Impl.instMonadLiftUnquoteMStateTUnquoteStateDelabM
 - StateT.instAlternative
 - StateT.instAlternativeMonad
 - StateT.instLawfulAlternativeLiftOfLawfulAlternativeOfLawfulMonad
 - StateT.instLawfulAlternativeOfLawfulMonad
 - StateT.instLawfulMonad
 - StateT.instLawfulMonadLift
 - StateT.instMonad
 - StateT.instMonadExceptOf
 - StateT.instMonadFunctor
 - StateT.instMonadLift
 - StateT.monadControl
 - StateT.tryFinally
 - instMonadStateOfStateTOfMonad
 
A tuple-based state monad.
Actions in StateM σ are functions that take an initial state and return a value paired with a
final state.
Recovers from errors. The state is rolled back on error recovery. Typically used via the <|>
operator.
Fails with a recoverable error. The state is rolled back on error recovery.
Equations
Equations
- StateT.instAlternative = { toApplicative := Monad.toApplicative, failure := fun {α : Type ?u.23} => StateT.failure, orElse := fun {α : Type ?u.23} => StateT.orElse }
 
Replaces the mutable state with a new value.
Equations
- StateT.set s' x✝ = pure (PUnit.unit, s')
 
Applies a function to the current state that both computes a new state and a value. The new state replaces the current state, and the value is returned.
It is equivalent to do let (a, s) := f (← StateT.get); StateT.set s; pure a. However, using
StateT.modifyGet may lead to better performance because it doesn't add a new reference to the
state value, and additional references can inhibit in-place updates of data.
Equations
- StateT.modifyGet f s = pure (f s)
 
Runs an action from the underlying monad in the monad with state. The state is not modified.
This function is typically implicitly accessed via a MonadLiftT instance as part of automatic
lifting.
Equations
- StateT.instMonadLift = { monadLift := fun {α : Type ?u.18} => StateT.lift }
 
Equations
- One or more equations did not get rendered due to their size.
 
Creates a suitable implementation of ForIn.forIn from a ForM instance.
Equations
- One or more equations did not get rendered due to their size.
 
Equations
- instMonadStateOfStateTOfMonad = { get := StateT.get, set := StateT.set, modifyGet := fun {α : Type ?u.18} => StateT.modifyGet }
 
Equations
- One or more equations did not get rendered due to their size.
 
Equations
- One or more equations did not get rendered due to their size.