I am reading the Scala with Cats book available here: https://books.underscore.io/scala-with-cats/scala-with-cats.html
There is a code sample in the book that I have a question about.
Basically, there is an extra underscore in the code whose purpose I don't understand. Is it a typo, or does the underscore serve some purpose?
import cats.Monoid
import cats.instances.int._ // for Monoid
import cats.instances.invariant._ // for Semigroupal
import cats.instances.list._ // for Monoid
import cats.instances.string._ // for Monoid
import cats.syntax.apply._ // for imapN
case class Cat(
name: String,
yearOfBirth: Int,
favoriteFoods: List[String]
)
val tupleToCat: (String, Int, List[String]) => Cat =
Cat.apply _
val catToTuple: Cat => (String, Int, List[String]) =
cat => (cat.name, cat.yearOfBirth, cat.favoriteFoods)
implicit val catMonoid: Monoid[Cat] = (
Monoid[String],
Monoid[Int],
Monoid[List[String]]
).imapN(tupleToCat)(catToTuple)
I am referring to the definition of the tupleToCat class. What is the purpose of the underscore after Cat.apply?