androidengineers.Book a session
โ† All interview questions
KotlinIntermediate4 min

Higher Order Functions in Kotlin?

Answer

A Higher-Order Function is a function that:

  1. Takes another function as a parameter.
  2. OR returns a function.

Example

// Takes a function 'operation'
fun calculate(a: Int, b: Int, operation: (Int, Int) -> Int): Int {
    return operation(a, b)
}

// Usage
val sum = calculate(5, 10) { x, y -> x + y }
val mul = calculate(5, 10) { x, y -> x * y }

This is the foundation of Kotlin's functional programming features like map, filter, and callbacks.

Mark this when you can explain the answer in your own words.

Share & Help Others

Help fellow developers prepare for interviews

Sharing helps the Android community grow ๐Ÿ’š

Keep practising