我有一个工作代码:
final case class Services[F[_]](c: Client[F], fooUrl: String)
(implicit cf: ConcurrentEffect[F]) {
private val dsl = Http4sDsl[F]
import dsl._
def routes: HttpRoutes[F] = HttpRoutes.of[F] {
case GET -> Root / "call" =>
c.get(fooUrl) { res =>
Applicative[F].pure {
Response[F]().withEntity {
res
.body
.through(text.utf8Decode)
.map(msg => "Forwarded through Boo" |+| msg)
}
}
}
}
当我删除隐式 importimplicit cf: ConcurrentEffect[F]
时,编译器会抱怨:
[error] /home/developer/scala/boo-service/src/main/scala/com/sweetsoft/Services.scala:29:20: could not find implicit value for parameter instance: cats.Applicative[F]
[error] Applicative[F].pure {
[error] ^
[error] /home/developer/scala/boo-service/src/main/scala/com/sweetsoft/Services.scala:26:48: could not find implicit value for evidence parameter of type cats.Defer[F]
[error] def routes: HttpRoutes[F] = HttpRoutes.of[F] {
[error] ^
[error] two errors found
我怎么知道,implicit cf: ConcurrentEffect[F]
缺少类型类?