What will be the result of applying function combine for semigroup of functions Int => Int?
import cats.implicits._
import cats.kernel.Semigroup

Semigroup[Int => Int].combine(_ + 1, _ * 10).apply(6)
Explanation
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

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Scala
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести