Higher Order Functions in Scala Last Updated : 15 Apr, 2019 Comments Improve Suggest changes Like Article Like Report A function is called Higher Order Function if it contains other functions as a parameter or returns a function as an output i.e, the functions that operate with another functions are known as Higher order Functions. It is worth knowing that this higher order function is applicable for functions and methods as well that takes functions as parameter or returns a function as a result. This is practicable as the compiler of Scala allows to force methods into functions. Some important points about Higher order functions: The Higher order functions are possible, as Scala programming language acts towards the functions as first-class values, which implies that analogous to some other values, functions can even be passed as a parameter or can be returned as an output, which is helpful in supplying an adjustable method for writing codes. It is beneficial in producing function composition where, functions might be formed from another functions. The function composition is the method of composing where a function shows the utilization of two composed functions. It is also constructive in creating lambda functions or anonymous functions. The anonymous functions are the functions which does not has name, though perform like a function. It is even utilized in minimizing redundant lines of code from a program. Now, lets see some examples. Example : Scala // Scala program of higher order // function // Creating object object GfG { // Main method def main(args: Array[String]) { // Displays output by assigning // value and calling functions println(apply(format, 32)) } // A higher order function def apply(x: Double => String, y: Double) = x(y) // Defining a function for // the format and using a // method toString() def format[R](z: R) = "{" + z.toString() + "}" } Output: {32.0} Here, the apply function contains an another function x with a value y and applies the function x to y. Example : Scala // Scala program of higher order // function // Creating object object GfG { // Main method def main(args: Array[String]) { // Creating a list of numbers val num = List(7, 8, 9) // Defining a method def multiplyValue = (y: Int) => y * 3 // Creating a higher order function // that is assigned to the variable val result = num.map(y => multiplyValue(y)) // Displays output println("Multiplied List is: " + result) } } Output: Multiplied List is: List(21, 24, 27) Here, map is a function that takes another function i.e, (y => multiplyValue(y)) as a parameter so, it is a higher order function. Comment More infoAdvertise with us Next Article Higher Order Functions in Scala N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Kotlin Higher-Order Functions Kotlin language has superb support for functional programming. Kotlin functions can be stored in variables and data structures, passed as arguments to and returned from other higher-order functions. Higher-Order FunctionIn Kotlin, a function that can accept a function as a parameter or return a func 6 min read Pure Function In Scala In any programming language, there are two types of functions: 1. PURE FUNCTIONS 2. IMPURE FUNCTIONSThere is a basic difference between the two, that is pure function doesnât change the variable itâs passed and an impure function does. For example, there exists a function which increases the input b 3 min read Partial Functions in Scala Introduction: When a function is not able to produce a return for every single variable input data given to it then that function is termed as Partial function. It can determine an output for a subset of some practicable inputs only. It can only be applied partially to the stated inputs. Some import 4 min read Scala | Nested Functions A function definition inside an another function is known as Nested Function. It is not supported by C++, Java, etc. In other languages, we can call a function inside a function, but itâs not a nested function. In Scala, we can define functions inside a function and functions defined inside other fu 2 min read Anonymous Functions in Scala In Scala, An anonymous function is also known as a function literal. A function which does not contain a name is known as an anonymous function. An anonymous function provides a lightweight function definition. It is useful when we want to create an inline function. Syntax: (z:Int, y:Int)=> z*yOr 2 min read Like