Working with optional data often creates repetitive pattern matches: unwrap a Some value, apply the business logic, then wrap the result again. Option.map removes that boilerplate while preserving the possibility of None. section 9.1.3
Option.map takes a function for the Some case. It applies that function when a value exists, wraps the result in Some, and leaves None unchanged. Ordinary functions therefore work with optional values without knowing about options. section 9.1.3
A manual transformation can be reduced to a pipeline:
- Verbose form: match customer with | Some c -> Some c.Age | None -> None. section 9.1.3
- Idiomatic form: customer |> Option.map (fun c -> c.Age). section 9.1.3
- Chain transformations with customer |> Option.map getAge |> Option.map classifyAge; each step continues only when the option contains Some. section 9.1.3
Compose before mapping
When getAge returns an int and classifyAge accepts an int, combine them as optionalCustomer |> Option.map (getAge >> classifyAge). This maps the option once and keeps getAge and classifyAge independent of optionality. section 9.1.3
Trace how a pipeline of operations transforms optional data while preserving the option container. section 9.1.3
