cats.mtl.Stateful
See theStateful companion object
trait Stateful[F[_], S] extends Serializable
Stateful[F, S]
is the capability to access and modify a state value from inside the F[_]
context, using set(s: S): F[Unit]
and get: F[S]
.
Stateful has four external laws:
def getThenSetDoesNothing = {
get >>= set <-> pure(())
}
def setThenGetReturnsSetted(s: S) = {
set(s) *> get <-> set(s) *> pure(s)
}
def setThenSetSetsLast(s1: S, s2: S) = {
set(s1) *> set(s2) <-> set(s2)
}
def getThenGetGetsOnce = {
get *> get <-> get
}
Stateful
has two internal law:
def modifyIsGetThenSet(f: S => S) = {
modify(f) <-> (inspect(f) flatMap set)
}
def inspectLaw[A](f: S => A) = {
inspect(f) <-> (get map f)
}
Attributes
- Companion
- object
- Source
- Stateful.scala
- Graph
-
- Supertypes
Members list
In this article