Option type
type Option<'Value> =
| None // Case without data β when value is missing
| Some of 'Value // Case with data β when value is presentModeling an optional field
type Civility = Mr | Mrs
type User = { Name: string; Civility: Civility option }
let joey = { Name = "Joey"; Civility = Some Mr }
let guest = { Name = "Guest"; Civility = None }Partial to total operation
Example 1: inverse of a number
Example 2: find an element in a collection
Benefits π
Control flow
Control flow with pattern matching
Control flow with Option.xxx helpers
Option.xxx helpersExercise
Example
Advantages
Option: comparison with other types
Option: comparison with other typesOption vs List
Option vs ListOption vs Nullable
Option vs NullableOption vs null
Option vs nullNullable reference types
Last updated