Function composing feeds the output of one function to the input of another function. Look at the implementation of compose and select the correct result of code execution
 def compose[A, B, C](f: B => C, g: A => B): A => C =
  a => f(g(a))

def f(b: Int): Int = b / 2
def g(a: Int): Int = a + 2

compose(f, g)(2)
compose(g, f)(2)
Explanation
Let’s see how composition of functions is performed step-by-step:
compose(f, g)(2)  
f(g(2))
(2 + 2) / 2
2

compose(g, f)(2)
g(f(2))
(2 / 2) + 2
3

Source: Scala Exercises: getting started with functional programming

Слідкуй за CodeGalaxy

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

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