Q1)what is higher-order function in Scala?
Ans:Functions which take other functions as parameters or return them as results are called higher-order functions.
Exmple:
Normal function
def square(x: Int): Int = x * x
High-order function:
def sumSquares(a: Int, b: Int): Int =
if (a > b) 0 else square(a) + sumSquares(a + 1, b)
No comments:
Post a Comment