For Semigroup[A => B] combine function is defined in the following way:
def combine(x: A => B, y: A => B): A => B =
(a: A) => Semigroup[B].combine(x(a), y(a))
Which means that initial expression boils down to
Semigroup[Int => Int].combine(_ + 1, _ * 10).apply(6) == Semigroup[Int].combine(6 + 1, 6 * 10) == Semigroup[Int].combine(7, 60)
For Semigroup[Int] combine function is defined as sum:
def combine(x: Int, y: Int): Int = x + y
Semigroup[Int].combine(7, 60) == (7 + 60) == 67
Source:
Scala Exercises: cats semigroup
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать