I was trying to create a new type class instance of Semigroup in Cats 2.7.0 for a case class called Expense. The problem occurs when the compiler throws an error telling me that the value instance does not exist for cats.kernel.Semigroup. Also, intellisense autocompletes all the other methods but the instance one.
I thought this could be done by using the instance method of the companion object of the Semigroup class, but it appears that it does not exists.
This is the code bellow:
object Semigroups extends App:
import cats.Semigroup // Type class import
// Expense class
case class Expense(id: Long, amount: Double)
// Creating the type class instance:
given expenseSemigroup: Semigroup[Expense] =
Semigroup.instance[Expense]( // <- the error ocurrs here
(exp1, exp2) =>
Expense(exp1.id + exp2.id, exp2.amount + exp1.amount)
)
end Semigroups
Maybe this method is depreciated now? What is the new one if it exists?
That's all, hope I made myself clear with this. Have everyone a nice day!