Option and Maybe Types
Model the presence or absence of a value explicitly.
Modeling Absence
Sometimes a value may simply be absent, with no error to report. An Option (also called Maybe) models presence or absence explicitly, an alternative to null and undefined.
Defining Option
Option is a discriminated union with a some tag. When some is true there is a value; when false there is nothing.
type Option<T> =
| { some: true; value: T }
| { some: false };All lessons in this course
- The Problem with Throwing Errors
- Modeling Result Types
- Option and Maybe Types
- Railway-Oriented Programming