map / filter / reduce: map transforms every element; filter keeps only matching elements; reduce folds a list into a single value. The three fundamental FP array operations. map, filter and reduce are the three basic operations for working with lists in a functional style. map transforms every item, filter keeps the items that match a condition, and reduce combines all items into one value, such as a total.
Frequently asked questions about map / filter / reduce
How is map / filter / reduce used in practice?
Together they replace most loops. "The total of paid orders" becomes filter on paid, map to amount, reduce by adding, and each step says exactly what it does.
What should you keep in mind with map / filter / reduce?
JavaScript arrays, Laravel collections, Python and almost every modern language offer them. Laravel adds handy shortcuts like sum(), pluck() and groupBy(). For very large data, remember that each step may create a new array; lazy collections or database queries avoid loading everything into memory. When the work can be done in SQL, letting the database aggregate is usually faster still.
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.