【发布时间】:2018-04-21 12:02:04
【问题描述】:
我有一些返回 IO 的代码,但我需要 http4s 中的 Effect。
import cats.effect.{Effect, IO}
class Service[F[_]: Effect] extends Http4sDsl[F] {
val service: HttpService[F] = {
HttpService[F] {
case GET -> Root =>
val data: IO[String] = getData()
data.map(d => Ok(d))
}
}
}
给予
[error] found : cats.effect.IO[F[org.http4s.Response[F]]]
[error] required: F[org.http4s.Response[F]]
[error] data.map(d => Ok(d))
[error] ^
【问题讨论】:
-
F在这里没有绑定到IO有什么原因吗?含义HttpService[IO]? -
这就是http4s模板的做法。如果像
HttpService[IO]一样,它确实有效。我假设它可以保持抽象和更好的一些方法。也许不是。?
标签: scala scala-cats http4s