小编sca*_*00b的帖子

Make F[_] implementing Monad trait while accepting IO

Let us say we have the code (<: Monad[F] doesn't work as expected):

class External[F[_] <: Monad[F] : Concurrent](implicit proxy: Proxy[F]) { ... }

class Proxy[F[_] <: Monad[F]](implicit storage: Storage, async: Async[F]) {
  def get(key: String): F[Option[Entry]] = {
    async.blocking(storage.get(key))
  }
}
Run Code Online (Sandbox Code Playgroud)

I would like F[_] to be a Monad, so that proxy.get() have those traits and enables for example (inside External class):

proxy.get(key).flatMap(...)
Run Code Online (Sandbox Code Playgroud)

So far so good, but when trying to instantiate with cats.effect.IO it doesn't work …

scala implicit typeclass scala-cats cats-effect

2
推荐指数
1
解决办法
452
查看次数

标签 统计

cats-effect ×1

implicit ×1

scala ×1

scala-cats ×1

typeclass ×1