final class IndexedReaderWriterStateT[F[_], E, L, SA, SB, A] extends Serializable
Represents a stateful computation in a context F[_]
, from state SA
to state SB
,
with an initial environment E
, an accumulated log L
and a result A
.
In other words, it is a pre-baked stack of ReaderT[F, E, A]
, WriterT[F, L, A]
and IndexedStateT[F, SA, SB, A]
.
- Alphabetic
- By Inheritance
- IndexedReaderWriterStateT
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new IndexedReaderWriterStateT(runF: F[(E, SA) ⇒ F[(L, SB, A)]])
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
bimap[SC, B](f: (SB) ⇒ SC, g: (A) ⇒ B)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SC, B]
Modify the resulting state using
f
and the resulting value usingg
. -
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @IntrinsicCandidate()
-
def
contramap[S0](f: (S0) ⇒ SA)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, S0, SB, A]
Modify the initial state using
f
. -
def
dimap[S0, S1](f: (S0) ⇒ SA)(g: (SB) ⇒ S1)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, S0, S1, A]
Modify the initial state using
f
and the resulting state usingg
. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
flatMap[SC, B](f: (A) ⇒ IndexedReaderWriterStateT[F, E, L, SB, SC, B])(implicit F: FlatMap[F], L: Semigroup[L]): IndexedReaderWriterStateT[F, E, L, SA, SC, B]
Modify the result of the computation by feeding it into
f
, threading the state through the resulting computation and combining the log values. -
def
flatMapF[B](faf: (A) ⇒ F[B])(implicit F: FlatMap[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B]
Like map, but allows the mapping function to return an effectful value.
-
def
get(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, SB]
Get the input state, without modifying it.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
-
def
inspect[B](f: (SB) ⇒ B)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B]
Inspect a value from the input state, without modifying the state.
-
def
inspectAsk[B](f: (E, SB) ⇒ B)(implicit F: Monad[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B]
Inspect a value from the environment and input state, without modifying the state.
Inspect a value from the environment and input state, without modifying the state.
scala> import cats.implicits._ scala> type Env = String scala> type Log = List[String] scala> val xOpt: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, Int] = IndexedReaderWriterStateT.get scala> val xAsk: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, String] = xOpt.inspectAsk(_ + _) scala> val input = 5 scala> xOpt.run("env", input) res0: Option[(Log, Int, Int)] = Some((List(),5,5)) scala> xAsk.run("env", 5) res1: Option[(Log, Int, String)] = Some((List(),5,env5))
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
listen(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, (A, L)]
Example:
Example:
scala> import cats.implicits._ scala> val x: IndexedReaderWriterStateT[Option, String, String, Int, Int, Unit] = IndexedReaderWriterStateT.tell("something") scala> val y: IndexedReaderWriterStateT[Option, String, String, Int, Int, (Unit, String)] = x.listen scala> y.run("environment", 17) res0: Option[(String, Int, (Unit, String))] = Some((something,17,((),something)))
-
def
local[EE](f: (EE) ⇒ E)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, EE, L, SA, SB, A]
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))
-
def
map[B](f: (A) ⇒ B)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B]
Modify the result of the computation using
f
. -
def
mapK[G[_]](f: ~>[F, G])(implicit F: Functor[F]): IndexedReaderWriterStateT[G, E, L, SA, SB, A]
Modify the context
F
using transformationf
. -
def
mapWritten[LL](f: (L) ⇒ LL)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, LL, SA, SB, A]
Modify the written log value using
f
. -
def
modify[SC](f: (SB) ⇒ SC)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SC, A]
Modify the resulting state.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
-
def
reset(implicit F: Functor[F], L: Monoid[L]): IndexedReaderWriterStateT[F, E, L, SA, SB, A]
Clear the log.
-
def
run(env: E, initial: SA)(implicit F: Monad[F]): F[(L, SB, A)]
Run the computation using the provided initial environment and state.
-
def
runA(env: E, initial: SA)(implicit F: Monad[F]): F[A]
Like run, but discards the final state and log.
-
def
runEmpty(env: E)(implicit F: Monad[F], SA: Monoid[SA]): F[(L, SB, A)]
Run the computation using the provided environment and an empty state.
-
def
runEmptyA(env: E)(implicit F: Monad[F], SA: Monoid[SA]): F[A]
Like runEmpty, but discards the final state and log.
-
def
runEmptyL(env: E)(implicit F: Monad[F], SA: Monoid[SA]): F[L]
Like runEmpty, but discards the final state and value.
-
def
runEmptyS(env: E)(implicit F: Monad[F], SA: Monoid[SA]): F[SB]
Like runEmpty, but discards the final value and log.
- val runF: F[(E, SA) ⇒ F[(L, SB, A)]]
-
def
runL(env: E, initial: SA)(implicit F: Monad[F]): F[L]
Like run, but discards the final state and value.
-
def
runS(env: E, initial: SA)(implicit F: Monad[F]): F[SB]
Like run, but discards the final value and log.
-
def
semiflatTransform[LL, SC, B](f: (L, SB, A) ⇒ F[(LL, SC, B)])(implicit F: Monad[F]): IndexedReaderWriterStateT[F, E, LL, SA, SC, B]
Like transform, but does it in the monadic context
F
.Like transform, but does it in the monadic context
F
.scala> import cats.implicits._ scala> type Env = String scala> type Log = List[String] scala> val xOpt0: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, Int] = IndexedReaderWriterStateT.get scala> val xOpt: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, Int] = xOpt0.tell("xxx" :: Nil) scala> val xHead: IndexedReaderWriterStateT[Option, Env, Log, Int, Int, String] = xOpt.semiflatTransform((l, s, a) => l.headOption.map(h => (l, s, h + a))) scala> val input = 5 scala> xOpt.run("env", input) res0: Option[(Log, Int, Int)] = Some((List(xxx),5,5)) scala> xHead.run("env", 5) res1: Option[(Log, Int, String)] = Some((List(xxx),5,xxx5))
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tell(l: L)(implicit F: Functor[F], L: Semigroup[L]): IndexedReaderWriterStateT[F, E, L, SA, SB, A]
Add a value to the log.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
transform[LL, SC, B](f: (L, SB, A) ⇒ (LL, SC, B))(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, LL, SA, SC, B]
Transform the resulting log, state and value using
f
. -
def
transformF[G[_], LL, SC, B](f: (F[(L, SB, A)]) ⇒ G[(LL, SC, B)])(implicit F: Monad[F], G: Applicative[G]): IndexedReaderWriterStateT[G, E, LL, SA, SC, B]
Like transform, but allows the context to change from
F
toG
.Like transform, but allows the context to change from
F
toG
.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))
-
def
transformS[R](f: (R) ⇒ SA, g: (R, SB) ⇒ R)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, R, R, A]
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))
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
written(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, L]
Retrieve the value written to the log.