import cats.data.ReaderT
import cats.instances.either._
trait Service1
trait Service2
case class Cats(name:String)
type FailFast[A] = Either[List[String], A]
type Env = (Service1, Service2, Cats)
type ReaderEnvFF[A] = ReaderT[FailFast, Env, A]
def toReaderEnvFF[A](input:A):ReaderEnvFF[A] =
ReaderT((_:Env) => Right(input))
def c:ReaderEnvFF[Cats] =
for {
cats <- toReaderEnvFF((_:Env)._3)
} yield cats // This line is 26
Error:
Error:(26, 11) type mismatch; found : T1.this.Env => com.savdev.Cats (which expands to) ((com.savdev.Service1, com.savdev.Service2, com.savdev.Cats)) => com.savdev.Cats required: com.savdev.Cats } yield cats
Can you please explain, why cats is not com.savdev.Cats
? And why in the error, it says that it is expanded to a function with return method [Cats]
, bot not FailFast[Cats]
I try to apply exactly the same logic as here:
trait Service1 { def s1f = Option(10) }
trait Service2 {
type ReaderS1[A] = ReaderT[Option,Service1,A]
import cats.syntax.applicative._
import cats.instances.option._
def s2f:ReaderS1[Int] =
for {
r2 <- ReaderT((_: Service1).s1f)
r1 <- 1.pure[ReaderS1]
} yield r1 + r2
}
In this example I could convert function Service1.s1f to its result r2 and it works fine. Why I cannot, for instance write something like:
for {
cats <- ReaderT((_:Env)._3)
...