I stumbled upon this problem when trying to implement a Bifunctior type class for maps (Bifunctor[Map[_, _]]
).
Bifunctor is defined like this in cats:
/**
* The quintessential method of the Bifunctor trait, it applies a
* function to each "side" of the bifunctor.
*
* Example:
* {{{
* scala> import cats.implicits._
*
* scala> val x: (List[String], Int) = (List("foo", "bar"), 3)
* scala> x.bimap(_.headOption, _.toLong + 1)
* res0: (Option[String], Long) = (Some(foo),4)
* }}}
*/
def bimap[A, B, C, D](fab: F[A, B])(f: A => C, g: B => D): F[C, D]
As the comment states, this function can be called using two functions (in one parameter group) as its input like this: x.bimap(_.headOption, _.toLong + 1)
. This tells me that this is clearly not the bimap
function being called since this one has two parameter groups ((fab: F[A, B])(f: A => C, g: B => D)
). I have been wondering if there is some kind of implicit type conversion that I am not aware of happening here. How does it work? What do I need to implement to get a Bifunctor type class for maps?