🐦 Kotlin
Beginner
What is a higher-order function in Kotlin?
Answer
A higher-order function is a function that takes another function as a parameter or returns a function. The parameter type is a function type, like (Int, Int) -> Int. Example: fun operate(a: Int, b: Int, op: (Int, Int) -> Int) = op(a, b), called as operate(3, 4) { x, y -> x + y }. Kotlin's entire collections API is built on higher-order functions — filter, map, forEach, reduce all take lambdas. This enables a functional programming style that is more expressive and composable than traditional loops.