Modify the resulting state using f
and the resulting value using g
.
Modify the initial state using f
.
Modify the initial state using f
and the resulting state using g
.
Modify the result of the computation by feeding it into f
, threading the state
through the resulting computation and combining the log values.
Like map, but allows the mapping function to return an effectful value.
Get the input state, without modifying it.
Inspect a value from the input state, without modifying the state.
Modify the initial environment using f
.
Modify the initial environment using f
.
scala> import cats.implicits._ scala> type Env = String scala> type GlobalEnv = (Int, Env) scala> type Log = List[String] scala> val xLocal: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, Int] = IndexedReaderWriterStateT.get scala> val xGlobal: IndexedReaderWriterStateT[Option, GlobalEnv, Log, Int, Int, Int] = xLocal.local(_._2) scala> val globalEnv: GlobalEnv = (5, "env") scala> xGlobal.run(globalEnv, 5) res0: Option[(List[String], Int, Int)] = Some((List(),5,5))
Modify the result of the computation using f
.
Modify the context F
using transformation f
.
Modify the written log value using f
.
Modify the resulting state.
Clear the log.
Run the computation using the provided initial environment and state.
Like run, but discards the final state and log.
Run the computation using the provided environment and an empty state.
Like runEmpty, but discards the final state and log.
Like runEmpty, but discards the final state and value.
Like runEmpty, but discards the final value and log.
Like run, but discards the final state and value.
Like run, but discards the final value and log.
Add a value to the log.
Transform the resulting log, state and value using f
.
Like transform, but allows the context to change from F
to G
.
Like transform, but allows the context to change from F
to G
.
scala> import cats.implicits._ scala> type ErrorOr[A] = Either[String, A] scala> type Env = String scala> type Log = List[String] scala> val xError: IndexedReaderWriterStateT[ErrorOr, Env, Log, Int, Int, Int] = IndexedReaderWriterStateT.get scala> val xOpt: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, Int] = xError.transformF(_.toOption) scala> val input = 5 scala> xError.run("env", input) res0: ErrorOr[(Log, Int, Int)] = Right((List(),5,5)) scala> xOpt.run("env", 5) res1: Option[(Log, Int, Int)] = Some((List(),5,5))
Transform the state used.
Transform the state used. See StateT for more details.
scala> import cats.implicits._ // needed for StateT.apply scala> type Env = String scala> type Log = List[String] scala> type S[SA, SB, A] = IndexedReaderWriterStateT[Option, Env, Log, SA, SB, A] scala> type GlobalEnv = (Int, String) scala> val x: S[Int, Int, Double] = IndexedReaderWriterStateT((env: Env, x: Int) => Option(("Addition" :: Nil, x + 1, x.toDouble))) scala> val xt: S[GlobalEnv, GlobalEnv, Double] = x.transformS[GlobalEnv](_._1, (t, i) => (i, t._2)) scala> val input = 5 scala> x.run("env", input) res0: Option[(Log, Int, Double)] = Some((List(Addition),6,5.0)) scala> xt.run("env", (input, "hello")) res1: Option[(Log, GlobalEnv, Double)] = Some((List(Addition),(6,hello),5.0))
Retrieve the value written to the log.
Represents a stateful computation in a context
F[_]
, from stateSA
to stateSB
, with an initial environmentE
, an accumulated logL
and a resultA
.In other words, it is a pre-baked stack of
ReaderT[F, E, A]
,WriterT[F, L, A]
andIndexedStateT[F, SA, SB, A]
.