0PricingLogin
Dart Academy · Lesson

fold, reduce, and expand

Aggregate and flatten iterables.

Aggregating a Collection

Often you want to collapse a whole list into one value, like a sum or a max. Dart gives you fold and reduce for exactly that. 🧮

Meet reduce

reduce combines elements pairwise using your function. It starts with the first item, so the list must not be empty.

var sum = [1, 2, 3, 4].reduce((a, b) => a + b);
print(sum); // 10

All lessons in this course

  1. Higher-Order Functions and Currying
  2. fold, reduce, and expand
  3. Lazy Iterables and Generators With sync*
  4. Composing Pure Function Pipelines
← Back to Dart Academy