Scala – Higher Order Function

Higher order Function is a functional programming principle that takes other functions as arguments or returns a function as output.

In this post, we are going to see that with an example.

Assume that we have a list of string and want to iterate it and append and prepend $ symbol to each value and collect the modified values as list. Refer the below example to know how we can do that with the higher-order function principle.

Scala Higher order function

In the above example, “modifyList” is a higher order function as it takes the “format” function as an argument. The “format” function is performing the append and prepend operation to each value. This example is pretty simple one and we can do it without a higher order function.