StateT

public 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

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to StateT.

  • Initializes a StateT.

    Declaration

    Swift

    public init(_ runF: Kind<F, (S) -> Kind<F, (S, A)>>)

    Parameters

    runF

    An effect describing a function that receives a state and produces an effect that updates the state and productes a value.

  • Runs this computation provided an initial state.

    Declaration

    Swift

    public func run(_ initialState: S) -> (S, A)

    Parameters

    initialState

    Initial 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

    public func runA(_ s: S) -> A

    Parameters

    s

    Initial state for this computation.

    Return Value

    Produced value from this computation.

  • Runs this computation provided an initial state.

    Declaration

    Swift

    public func runS(_ s: S) -> S

    Parameters

    s

    Initial 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

    f

    Transforming function.

    Return Value

    An StateT where the final state and produced value have been transformed using the provided function.

  • Lifts an effect by wrapping the contained value into a function that depends on some state.

    Declaration

    Swift

    public static func liftF(_ fa: Kind<F, A>) -> StateT<F, S, A>

    Parameters

    fa

    Value to be lifted.

    Return Value

    A StateT that produces the contained value in the original effect, preserving the state.

  • Runs this computation using the provided initial state.

    Declaration

    Swift

    public func runA(_ s: S) -> Kind<F, A>

    Parameters

    s

    Initial 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

    s

    Initial 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

    initial

    Initial state to run this computation.

    Return Value

    A pair with the new state and produced value, wrapped in the effect.

  • Zips this computation with another one depending on the same state and effect types and combines the produced values using the provided function.

    Declaration

    Swift

    public func map2<B, Z>(_ sb: StateT<F, S, B>, _ f: @escaping (A, B) -> Z) -> StateT<F, S, Z>

    Parameters

    sb

    Another state computation.

    f

    Combining function.

    Return Value

    An StateT with the combination of the results of the two state computations, using the provided function.

  • 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

    f

    A function producing an effect.

    Return Value

    Result of flatmapping and lifting the function to this value.