kotlin arrow function

// Step 1: Define a function using arrow syntax
val add: (Int, Int) -> Int = { x, y -> x + y }

// Step 2: Call the function
val result = add(5, 3)

// Step 3: Print the result
println("Result: $result")

Explanation:

  1. Declare a function named add with the arrow syntax. It takes two parameters of type Int and returns an Int. The function body, { x, y -> x + y }, adds the two parameters and returns the result.

  2. Call the add function with arguments 5 and 3. The result is assigned to the variable result.

  3. Print the result using println. The output will be "Result: 8" in this example.