Comparison
First-class functionvsHigher-order function
First-class function
you put the function in a variable, passed it to something and returned it from somewhere else, like any other value.
A language property: functions can be stored, passed and returned like any other value. It is the feature that collapses several patterns into ordinary code — a strategy becomes a parameter, a command becomes a closure, an observer becomes a list of functions. Saying that in an interview is a stronger answer than reciting the class diagram for any of the three.
Full entry →Higher-order function
the function's argument is another function, and what it actually does depends entirely on what you passed.
A function that takes or returns another function. It is the mechanism behind map, filter, sort comparators, decorators, middleware and retry helpers — anywhere the shape of a computation is fixed and one step of it is not. The pattern-catalogue equivalents are strategy and template method, both of which reduce to a higher-order function in a language with closures.
Full entry →