Lably
Skip to content

Higher-order function

Function that takes one or more functions as an input or that outputs a function

  • 48 min read
  • 2 chapters

Related on Lably

Through Mathematics, Computer science and Function (mathematics)

  • takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itself a procedure),
  • returns a function as its result.

All other functions are first-order functions. In mathematics higher-order functions are also termed operators or functionals. The differential operator in calculus is a common example, since it maps a function to its derivative, also a function. Higher-order functions should not be confused with other uses of the word "functor" throughout mathematics, see Functor (disambiguation).

In the untyped lambda calculus, all functions are higher-order; in a typed lambda calculus, from which most functional programming languages are derived, higher-order functions that take one function as argument are values with types of the form (τ1→τ2)→τ3.

General examples

  • map function, found in many functional programming languages, is one example of a higher-order function. It takes arguments as a function f and a collection of elements, and as the result, returns a new collection with f applied to each element from the collection.
  • sort, which take a comparison function as a parameter, allowing the programmer to separate the sorting algorithm from the comparisons of the items being sorted. The C standard function qsort is an example of this.
  • filter function, that takes a collection and a function that returns true or false, and returns a new collection that is the elements of the parameter collection where the function returned true.
  • fold (including foldl and foldr)
  • scan
  • apply
  • Function composition
  • Integration
  • Callback
  • Tree traversal
  • Montague grammar, a semantic theory of natural language, uses higher-order functions

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication