DELAPARRA
Index
Color
NL
Category: Programming paradigms

map / filter / reduce

Explained by Updated

What is map / filter / reduce?

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.

Definition source Coders Lingo, CC BY 4.0

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.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with M

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.