Stateful

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
trait Serializable
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def get: F[S]

Attributes

Source
Stateful.scala
def monad: Monad[F]

Attributes

Source
Stateful.scala
def set(s: S): F[Unit]

Attributes

Source
Stateful.scala

Concrete methods

def inspect[A](f: S => A): F[A]

Attributes

Source
Stateful.scala
def modify(f: S => S): F[Unit]

Attributes

Source
Stateful.scala