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)
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))) …
SStateT[F[_], A, B](f: (A => F[(A, B)])) { def flatMap[C](fc: B => SStateT[F, A, C]) (implicit M: Monad[F]) = SStateT[F, A, C](a => { f(a).flatMap(aa => aa match { //returns the F[(A,C)] case (aaa, b) => fc(b).f(aaa) }) }) }
SStateT[F[_], A, B](f: (A => F[(A, B)])) { def flatMap[C](fc: B => SStateT[F, A, C]) (implicit M: Monad[F]) = SStateT[F, A, C](a => { f(a).flatMap(aa => aa match { //returns the F[(A,C)] case (aaa, b) => fc(b).f(aaa) }) }) }
SStateT[F[_], A, B](f: (A => F[(A, B)])) { def flatMap[C](fc: B => SStateT[F, A, C]) (implicit M: Monad[F]) = SStateT[F, A, C](a => { f(a).flatMap(aa => aa match { //returns the F[(A,C)] case (aaa, b) => fc(b).f(aaa) }) }) }
SStateT[F[_], A, B](f: (A => F[(A, B)])) { def flatMap[C](fc: B => SStateT[F, A, C]) (implicit M: Monad[F]) = SStateT[F, A, C](a => { f(a).flatMap(aa => aa match { //returns the F[(A,C)] case (aaa, b) => fc(b).f(aaa) }) }) }
Task { cis.map.lookup(i) match { case Some(item) => (cis, item) case None => val item = viewItemUnsafe(i) val nmap = cis.map + (i -> item) (CachedState(nmap), item) } })
_ <- 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!