There is a basic misunderstanding. Those members like
chain etc. belong to the singleton object
Function, not members of “Function types” as you interpreted.
In the REPL you would use them as:
Welcome to Scala 3.1.2 (11.0.15, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> val f: (Int => Int) = x => x * 2
val f: Int => Int = Lambda$1295/0x0000000840689040@70c56434
scala> val g: (Int => Int) = x => x * x
val g: Int => Int = Lambda$1313/0x00000008406b3840@269c7104
scala> val h = Function.chain(Seq(f,g))
val h: Int => Int = scala.Function$$$Lambda$1426/0x0000000840740040@73aae7a
val res0: Int = 16
As far as I can tell, the syntax in the “Tour of Scala” works, so I’m guessing you were mixing
Function into it somehow.
I don’t think anyone would define functions by directly using types like
Function2[...]. At least I’ve never seen it outside of some academic explanations. These are all underlying implementation details of how Scala desugars our “normal” definitions. If I understand correctly (someone can correct me if I’m wrong), whenever we define a function value, Scala compiler creates an anonymous class instance that extends the appropriate trait
FunctionN depending on the number of arguments… but nobody should bother to know that! It’s all hidden from us for good reason.
You seem to be making a very common mistake that so many others are making: trying to learn the language from documentation (not blaming you!). Please don’t do that! It’s like trying to learn a foreign language purely from a dictionary. It naturally leads to these misconceptions and makes you lose a ton of time. Documentation should be used for reference purposes only (just like a dictionary).
Instead take an online course or pick up a book. I recommend either “Get Programming with Scala” by Daniela Sfregola, or “Programming in Scala 5th Edition” by Odersky (which explains what a singleton object is in one of the earlier chapters on OOP).