Sitemap

Dart is an approachable, portable, and productive language for high-quality apps on any platform. Learn more at https://dart.dev.

Dart 3.1 & a retrospective on functional style programming in Dart 3

Image for: Pattern matching and exhaustive switches come together to enable functional style data models that b
12 min readAug 16, 2023

--

Diff of a Dart 3 refactor using functional style features within Dart’s internal code base

How do you model data?

Simplified side-by-side comparison of the object-oriented class hierarchy model and the functional algebraic data type model

Object-oriented approach

Image for: Object-oriented approach

Functional approach (algebraic data types)

Image for: Functional approach (algebraic data types)

Modeling object oriented algebraic data types

Grouping behaviors across types

Image for: Grouping behaviors across types
Annotated depiction of the syntax for a deeply nested object and variable patterns

Exhaustiveness checking

Image for: Exhaustiveness checking
The type 'FileSystemEvent' is not exhaustively matched by the switch cases since it doesn't match 'FileSystemSyncEvent'

Bonus functional features

Image for: Bonus functional features

Summary

Resources

Image for: Resources

--

--

Published in Dart

Image for: Published in Dart

Dart is an approachable, portable, and productive language for high-quality apps on any platform. Learn more at https://dart.dev.

Responses (11)

Image for: Responses (11)