cats icon indicating copy to clipboard operation
cats copied to clipboard

contramapN should come from syntax.contravariant._

Open mrdziuban opened this issue 5 years ago • 2 comments

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

mrdziuban avatar Feb 28 '20 13:02 mrdziuban

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.

travisbrown avatar Feb 28 '20 14:02 travisbrown

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.

vasilmkd avatar Jul 08 '20 13:07 vasilmkd