S2, A] { self => def getF[S <: S1]: Monad[F] => F[S => F[(S2, A)]] ! /** Run and return the final value and state in the context of `F` */ def apply(initial: S1)(implicit F: Monad[F]): F[(S2, A)] = F.join(F.map[S1 => F[(S2, A)], F[(S2, A)]](getF(F))(sf => sf(initial))) …
that a stateful computation is a function that takes some state and returns a value along with some new state. That function would have the following type: ! A => (A, B) ! ! !
case class CacheState(map: IMap[Int, Item])! ! class LockedState(map: IMap[Int, Item]) extends CacheState(map)! ! class UpdatedState(map: IMap[Int, Item]) extends LockedState(map)
_ <- lockItem(4)! } yield (a)! ! Has the following error:! ! found : IndexedStateT[Task,cmd5.LockedState,LockedState, Item]! (which expands to) IndexedStateT[Task, cmd5.LockedState,LockedState,String]! required: IndexedStateT[Task,cmd4.CachedState,?,?]! _ <- updateItemName(4, “asdf")! ! We need a regular CachedState, not a Locked State! View Item doesn’t return a LockedItem
to) IndexedStateT[Task, cmd5.LockedState,LockedState,String]! required: IndexedStateT[Task,cmd4.CachedState,?,?]! _ <- updateItemName(4, “asdf") We can’t pass in a CacheState to something expecting a LockedState, so the types don’t work out!