Higher Order Functions
# Scala Higher-Order Functions
[ Scala Functions](#)
A higher-order function is a function that operates on other functions.
Scala allows the use of higher-order functions. Higher-order functions can use other functions as parameters, or use functions as output results.
In the following example, the apply() function uses another function f and a value v as parameters, and the function f then calls the parameter v:
object Test {
def main(args: Array) {
println( apply( layout, 10) )
}
// Function f and value v as parameters, and function f then calls parameter v
def apply(f: Int => String, v: Int) = f(v)
def layout(x: A) = "[" + x.toString() + "]"
}
Execute the above code, the output result is:
$ scalac Test.scala
$ scala Test
[ Scala Functions](#)
YouTip