Here is an example that works fine:
import cats.data.ReaderT
import cats.instances.option._
...
def f1:ReaderT[Option, Service, Int] =
ReaderT(service => for {
res <- Some(10)
} yield res )
Here is an example that is not compiled:
def f2:ReaderT[Option, Service, Int] =
for {
res <- ReaderT((_:Service) => Some(10))
} yield res
I get the following error:
Error:(53, 11) could not find implicit value for parameter F: cats.Functor[Some] res <- ReaderT((:Service) => Some(10)) Error:(53, 11) not enough arguments for method map: (implicit F: cats.Functor[Some])cats.data.Kleisli[Some,com.savdev.Service,Int]. Unspecified value parameter F. res <- ReaderT((:Service) => Some(10))
To fix the error in the 2nd example, I must return not Some
, but Option
, which is a parent for Some
:
def f2:ReaderT[Option, Service, Int] =
for {
res <- ReaderT((_:Service) => Option(10))
} yield res
Can you please explain this? Why in the 1st example returning Some
, but not Option
, works fine. Why at the same time in the 2nd example, returning Some
is not compiled? Is there an option for Scala compiler to compile cases, like in the 2nd example? Or other solution.