Search code examples
scalafunctional-programmingscala-cats

How to enforce F[_] to be an instance of Monad


I have the following class definition:

final case class Creator[F[_]](topic: String, discovery: ServiceDiscovery[F])
                                     (implicit sync: Sync[F]) {
  import JsonDeserializer._

  private def setting: ConsumerSettings[F, String, JsonDecoder] =
     discovery
       .kafkaAddr

I would like to enforce F[_] to be an instance of Monad, that I can use flatMap like:

 private def setting: ConsumerSettings[F, String, JsonDecoder] =
     discovery
       .kafkaAddr
       .flatMap.......

How can I archive it?


Solution

  • Import syntax

    import cats.syntax.flatMap._
    

    Since cats.effect.Sync extends cats.Monad (and cats.FlatMap) and you have implicit sync: Sync[F] this should be enough.