Function Composition in Scala

I am trying to write a function that takes two functions and composes them. I tried the solution below and a few other options, but not many.

def compose1[A, B, C](f: A => B, g: B => C)(x: A) = f(g(x))

The error I get is

<console>:21: error: type mismatch;
 found   : x.type (with underlying type A)
 required: B
       def compose1[A, B, C](f: A => B, g: B => C)(x: A) = f(g(x))
                                                               ^

Full disclosure is part of a university exercise designed to teach us Scala, although this is not for credit. The question is really poorly worded (it was literally an expression about the function and the sentence I used above), and there were no examples or explanations given in front of you, I think that I do not have a good understanding of Scala to understand the question. I would be very grateful for the study of the problem, thanks for the help!

+4
source share
1 answer

: x (type A) g ( B C). , .

+3

Source: https://habr.com/ru/post/1657054/


All Articles