I have this code which compiles and works fine
import cats.implicits._
Cartesian[ValidResponse].product(
getName(map).toValidated,
readAge(map).toValidated
).map(User.tupled)
However I don't like the import of cats.implicits._
because there is just too many classes there. I tried importing specific things related to Cartesians like
import cats.implicits.catsSyntaxCartesian
import cats.implicits.catsSyntaxUCartesian
import cats.implicits.catsSyntaxTuple2Cartesian
But these did not work. As a newbie I find the implicit imports very confusing because there are simply 1000s of them and the names are not very obvious. My only alternative is to import the entire universe by import cats.implicits._
and stop thinking about it.
In fact I have a broader confusion about cats.implicits
, cats.instances._
and cats.syntax._
. So far I am just importing these via trial and error. I am not really sure of when to import what.
Do not try to pick out specific things from
cats.implicits
. You either import the entire thing, or you don't use it at all. Further, there's no reason to be afraid of importing it all. It can't interfere with anything.Ok, I lied. It will interfere if you import
cats.instances.<x>._
and/orcats.syntax.<x>._
alongsidecats.implicits._
. These groups are meant to be mutually exclusive: you either import everything and forget about it withcats.implicits._
, or you specifically select what you want to import withcats.instances
andcats.syntax
.These two packages are not meant to be imported completely like
cats.implicits
. Instead, they include a bunch of objects. Each object contains some implicit instances/syntax, and you are meant to import from those.Additionally each of
cats.{ instances, syntax }
contains anall
object, with the obvious function. The importcats.implicits._
is really a shortcut forimport cats.syntax.all._, cats.instances.all._
.