In Chapter 9 of Programming In Scala, there is an example method like this:
def twice(op: Double => Double, x: Double) = op(op(x))
The
In addition to separating the parameter list from the function body in a function literal, the double arrow can be used as syntactic sugar for a FunctionN type:
T => R
means Function1[T, R]
(T1, T2) => R
means Function2[T1, T2, R]
...
In your example, this means that op
is a function that takes a Double and returns a Double (as the author explained).
As another example, it's possible to write
// declare len as a function that takes a String and returns an Int,
// and define it as returning the length of its argument
val len: String => Int = { _.length }
// or, a more verbose version that uses '=>' in both ways
val len: String => Int = { (s: String) => s.length }
len("apple") // returns 5