Free preview.You're sampling one lesson — enroll free to unlock all 8 lessons and track your progress.
Enroll free lesson
Pure Functions
Pure Functions
In this lesson — part of Functional Foundations — you'll learn pure functions in Dart and why it matters in real work.
Why it matters
Functional style — pure functions and immutability — makes code easier to test and reason about.
Key ideas
- Pure functions
- Immutability
- No shared mutable state
- Predictable outputs
In practice
Here's how it looks in idiomatic Dart:
int square(int x) => x * x; // pure: no side effects, output depends only on input
void main() {
print(square(5)); // 25
print(square(5)); // 25, always identical
}
Dart note: Dart treats functions as first-class values, so a pure top-level function like this can be passed around and reused freely.
Try it yourself
Exercise: In Dart, rewrite a function that mutates a global so it's pure.
Recap
You now understand pure functions and can apply it in Dart. Mark this lesson complete and continue to the next one.
