What are higher order functions?

‹ What is lazy evaluation? | What is MapReduce? ›

A higher order function is one that either takes functions as parameters or returns functions as return values. They are often used in place of loops in functional programming languages since a pure function cannot have a mutable loop iteration variable.

Some commonly used higher order functions are:

  • map(func, in_list) which runs the function on every input list element and returns the resulting list [func(in_list[0]), func(in_list[1]), func(in_list[2]), ....]
  • fold(func, zero, in_list), sometimes called reduce(), which iterates over the input list and aggregates each element into a final aggregated result or results like sum, count, average, min, max, etc.
  • filter(func, in_list) which will run the provided function on every input list element and return a list of elements where the function was true.
Subscribe to All Posts - Wesley Tanaka