concept high - order function in category functional programming

appears as: Higher-order functions, higher-order function, A higher-order function, The higher-order function
Grokking Functional Programming

This is an excerpt from Manning's book Grokking Functional Programming.

lang => lang.name

becomes

_.name

What we do is we don't need to name the incoming parameter and just say we are interested only in one of its fields. _ is still a value of type ProgrammingLanguage, but it's not named explicitly.

lang => lang.year > 2000

becomes

_.year > 2000
Functional Programming with Kotlin

This is an excerpt from Manning's book Functional Programming with Kotlin.

An unzip is then used to destructure the list of pairs into two separate lists, each representing one side of the Pair. Destructuring is the process of extracting values from a complex data type. We are now left with the coffees list being a List<Coffee>, and charges being a List<Charge>. The final step involves reconstructing the data into the required output. This is done by constructing a Pair of List<Coffee> mapped to the combined Charges for all the Coffees in the list. reduce is an example of a higher-order function, which will be properly introduced in chapter 2.

3.4 Recursion over lists and generalizing to higher-order functions

Let’s look again at the implementations of sum and product. These two functions seem remarkably similar in what they do and how they go about doing it. Next, we will look at extracting commonalities to derive a higher-order function of these two functions.

Functional Programming in C++

This is an excerpt from Manning's book Functional Programming in C++.

We’ll start with basic concepts such as higher-order functions, which allow you to increase the expressiveness of the language and make your programs shorter, and how to design software without mutable state to avoid the problems of explicit synchronization in concurrent software systems. After this, we’ll switch to second gear and cover more-advanced topics such as ranges (the truly composable alternative to standard library algorithms) and algebraic data types (which you can use to reduce the number of states a program can be in). Finally, we’ll discuss one of the most talked-about idioms in FP—the infamous monad —and how you can use various monads to implement complex, highly composable systems.

Functions that take other functions as arguments or that return new functions are called higher-order functions. They’re probably the most important concept in FP. In the previous chapter, you saw how to make programs more concise and efficient by describing what the program should do on a higher level with the help of standard algorithms, instead of implementing everything by hand. Higher-order functions are indispensable for that task. They let you define abstract behaviors and more-complex control structures than those provided by the C++ programming language.

Functional Programming in Scala

This is an excerpt from Manning's book Functional Programming in Scala.

Listing 1.3. Buying multiple cups with buyCoffees
class Cafe { def buyCoffee(cc: CreditCard): (Coffee, Charge) = ... def buyCoffees(cc: CreditCard, n: Int): (List[Coffee], Charge) = { #1 val purchases: List[(Coffee, Charge)] = List.fill(n)(buyCoffee(cc)) #2 val (coffees, charges) = purchases.unzip #3 (coffees, charges.reduce((c1,c2) => c1.combine(c2))) #4 } } #1: TList[Coffee] is an immutable singly linked list of Coffee values. We’ll discuss this data type more in chapter 3. #2: List.fill(n)(x) creates a List with n copies of x. We’ll explain this funny function call syntax in a later chapter. #3: unzip splits a list of pairs into a pair of lists. Here we’re destructuring this pair to declare two values (coffees and charges) on one line. #4: charges.reduce reduces the entire list of charges to a single charge, using combine to combine charges two at a time. reduce is an example of a higher-order function, which we’ll properly introduce in the next chapter.