Free preview.You're sampling one lesson — enroll free to unlock all 10 lessons and track your progress.
Enroll free
lesson

Closures and Higher-Order Functions

Closures and Higher-Order Functions

In this lesson — part of Advanced Features — you'll learn closures and higher-order functions in Dart and why it matters in real work.

Why it matters

Functions that take or return functions unlock concise, composable code.

Key ideas

  • Functions as values
  • map / filter / reduce
  • Callbacks
  • Composition

In practice

Here's how it looks in idiomatic Dart:

void main() {
  var nums = [1, 2, 3, 4, 5, 6];
  var result = nums
      .where((n) => n.isEven)   // filter
      .map((n) => n * 10)        // transform
      .toList();
  print(result); // [20, 40, 60]
}

Dart note: In Dart, map/where are lazy and return an Iterable, so you call .toList() to materialize the result (where is Dart's filter).

Try it yourself

Exercise: In Dart, use map and filter to get the squares of the even numbers.

Recap

You now understand closures and higher-order functions and can apply it in Dart. Mark this lesson complete and continue to the next one.