DELAPARRA
Index
Color
NL
Category: Programming paradigms

Higher-Order Function

Explained by Updated

What is Higher-Order Function?

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.

Definition source Coders Lingo, CC BY 4.0

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.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with H

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.