Higher-order functions (HOF)

One function can take an input argument as another function and it can return a function. This originated from calculus and is widely used in functional programming. Order can be determined by domain and range of order such as order 0 has no function data and order 1 has a domain and range of order 0, if order is higher than 1, it is called a higher-order function. For example, the ComplexCalc function takes another function as input and returns a different function as output:

open Systemlet sum y = x+xlet divide y = x/xLet ComplexCalc func = (func 2)Printfn(ComplexCalc sum) // 4Printfn(ComplexCalc divide) //1

In the previous example, we created two functions, sum and divide. We pass these two functions as parameters ...

Get .NET Core 2.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.