StateT
public final class StateT<F, S, A> : StateTOf<F, S, A>
StateT transformer represents operations that need to write and read a state through a computation or effect.
Some computations may not require the full power of this transformer:
- For read-only state, see ReaderT / Kleisli.
- To accumulate a value without using it on the way, see WriterT.
-
Safe downcast.
Declaration
Swift
public static func fix(_ fa: StateTOf<F, S, A>) -> StateT<F, S, A>Parameters
faValue in the higher-kind form.
Return Value
Value cast to StateT.
-
Initializes a
StateT.Declaration
Swift
public init(_ runF: @escaping (S) -> Kind<F, (S, A)>)Parameters
runFAn effect describing a function that receives a state and produces an effect that updates the state and productes a value.
-
Generalizes this StateT to a parent state, given a lens to focus from the parent to the child state.
Declaration
Swift
func focus<SS>(_ lens: Lens<SS, S>) -> StateT<F, SS, A>Parameters
lensA Lens to focus from the parent state into the child state.
Return Value
An
StateTthat produces the same computation but updates the state in a parent state.
-
Initializes a
Statevalue.Declaration
Swift
convenience init(_ run: @escaping (S) -> (S, A))Parameters
runA function that depends on a state and produces a new state and a value.
-
Runs this computation provided an initial state.
Declaration
Swift
func run(_ initialState: S) -> (S, A)Parameters
initialStateInitial state for this computation.
Return Value
A pair with the updated state and the produced value.
-
Runs this computation provided an initial state.
Declaration
Swift
func runA(_ s: S) -> AParameters
sInitial state for this computation.
Return Value
Produced value from this computation.
-
Runs this computation provided an initial state.
Declaration
Swift
func runS(_ s: S) -> SParameters
sInitial state for this computation.
Return Value
Updated state after running the computation.
-
Transforms the return value and final state of a computation using a provided function.
Declaration
Swift
public func transform<B>(_ f: @escaping (S, A) -> (S, B)) -> StateT<F, S, B>Parameters
fTransforming function.
Return Value
An
StateTwhere the final state and produced value have been transformed using the provided function. -
Transforms the wrapped value using a provided function.
Declaration
Parameters
fTransforming function.
Return Value
An
StateTwhere the final state and produced value have been transformed using the provided function. -
Generalizes this StateT to a parent state, given functions to get and set the inner state into the general state.
Declaration
Swift
public func focus<SS>(_ getter: @escaping (SS) -> S, _ setter: @escaping (SS, S) -> SS) -> StateT<F, SS, A>Parameters
getterFunction to get the state from the parent.
setterFunction to set the state into the parent.
Return Value
An
StateTthat produces the same computation but updates the state in a parent state.
-
Runs this computation using the provided initial state.
Declaration
Swift
public func runA(_ s: S) -> Kind<F, A>Parameters
sInitial state to run this computation.
Return Value
Result of running this computation with the provided state, wrapped in the effect.
-
Runs this computation using the provided initial state.
Declaration
Swift
public func runS(_ s: S) -> Kind<F, S>Parameters
sInitial state to run this computation.
Return Value
New state after running this computation with the provided state, wrapped in the effect.
-
Runs this computation using the provided initial state.
Declaration
Swift
public func runM(_ initial: S) -> Kind<F, (S, A)>Parameters
initialInitial state to run this computation.
Return Value
A pair with the new state and produced value, wrapped in the effect.
-
Modifies the state with a function and returns unit.
Declaration
Swift
public func modifyF(_ f: @escaping (S) -> Kind<F, S>) -> StateT<F, S, ()>Parameters
fFunction to modify the state.
Return Value
A StateT value with a modified state and unit as result value.
-
Sets the state to a specific value and returns unit.
Declaration
Swift
public func setF(_ fs: Kind<F, S>) -> StateT<F, S, ()>Parameters
fsValue to set the state.
Return Value
A StateT value with a modified state and unit as result value.
-
Flatmaps a function that produces an effect and lifts if back to
StateT.Declaration
Swift
public func semiflatMap<B>(_ f: @escaping (A) -> Kind<F, B>) -> StateT<F, S, B>Parameters
fA function producing an effect.
Return Value
Result of flatmapping and lifting the function to this value.
Install in Dash
StateT Class Reference