Higher-Order Function: A function that takes another function as a parameter or returns one. map(), filter(), and reduce() are classic examples. A higher-order function takes a function as an argument, returns one, or both. array_map, array_filter and usort in PHP, and map, filter and reduce in JavaScript, are everyday examples. They let you separate what you do with each item from how you loop over the items. array_filter($orders, fn ($o) => $o->isPaid()) says exactly what it means, without loop bookkeeping.
Frequently asked questions about Higher-Order Function
What should you keep in mind with Higher-Order Function?
They also enable reusable building blocks. A function like retry($callback, 3) can wrap any operation that might fail, and middleware in web frameworks is essentially functions wrapping functions. Keep the passed-in functions small and clearly named. A long anonymous function inside a map is usually easier to read as a separate, named function.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.