cats.mtl
MonadState[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].
MonadState[F, S]
F[_]
set(s: S): F[Unit]
get: F[S]
MonadState 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 }
MonadState has two internal law:
MonadState
def modifyIsGetThenSet(f: S => S) = { modify(f) <-> (inspect(f) flatMap set) } def inspectLaw[A](f: S => A) = { inspect(f) <-> (get map f) }
MonadState[F, S]
is the capability to access and modify a state value from inside theF[_]
context, usingset(s: S): F[Unit]
andget: F[S]
.MonadState has four external laws:
MonadState
has two internal law: