Get the input state, without modifying the state.
Inspect a value from the input state, without modifying the state.
Modify the state (S
) component.
Run with the provided initial state value
Run with the provided initial state value and return the final value (discarding the final state).
Run with S
's empty monoid value as the initial state.
Run with S
's empty monoid value as the initial state and return the final
value (discarding the final state).
Run with S
's empty monoid value as the initial state and return the final
state (discarding the final value).
Run with the provided initial state value and return the final state (discarding the final value).
Like map, but also allows the state (S
) value to be modified.
Like transform, but allows the context to change from F
to G
.
Transform the state used.
Transform the state used.
This is useful when you are working with many focused StateT
s and want to pass in a
global state containing the various states needed for each individual StateT
.
scala> import cats.std.option._ // needed for StateT.apply scala> type GlobalEnv = (Int, String) scala> val x: StateT[Option, Int, Double] = StateT((x: Int) => Option((x + 1, x.toDouble))) scala> val xt: StateT[Option, GlobalEnv, Double] = x.transformS[GlobalEnv](_._1, (t, i) => (i, t._2)) scala> val input = 5 scala> x.run(input) res0: Option[(Int, Double)] = Some((6,5.0)) scala> xt.run((input, "hello")) res1: Option[(GlobalEnv, Double)] = Some(((6,hello),5.0))
StateT[F, S, A]
is similar toKleisli[F, S, A]
in that it takes anS
argument and produces anA
value wrapped inF
. However, it also produces anS
value representing the updated state (which is wrapped in theF
context along with theA
value.