cats
cats copied to clipboard
contramapN should come from syntax.contravariant._
When using a la carte imports, I need to import cats.syntax.apply._ to be able to call contramapN, but I expected to import cats.syntax.contravariant._. Here's a scastie to demonstrate: https://scastie.scala-lang.org/mrdziuban/IZmraJ4BRlugdmXfeUWoLg/3
I was just taking a look at this, and contramapN also requires a Semigroupal instance, so you'll need contravariantSemigroupal instead of contravariant, which does work now:
import cats.Eq
import cats.instances.eq._
import cats.instances.int._
import cats.instances.string._
import cats.syntax.contravariantSemigroupal._
case class Test(i: Int, s: String)
(Eq[Int], Eq[String]).contramapN((t: Test) => (t.i, t.s))
The current behavior is still wrong, though. There's definitely no reason syntax.apply._ should bring in contramapN, or that syntax.contravariantSemigroupal._ should give you e.g. traverseN.
It seems that all of these syntax functions come from TupleSemigroupalSyntax.scala which is autogenerated boilerplate code. Any ideas on how this should be handled? Should these TupleNSemigroupalOps classes be split into smaller classes offering 1 method each? (e.g. one class for mapN, one for imapN, one for contramapN, etc.)
Edit: I only see this occur for tuples.