Higher-Order Functions

A higher-order function takes other functions as parameters or returns a function.

Example

def applyTwice(f: Int => Int, x: Int): Int = f(f(x))
val double = (x: Int) => x * 2
println(applyTwice(double, 2)) // prints 8

They're widely used with collections for operations like map, filter, and fold.

← PrevNext →