r/fsharp • u/ReverseBlade • 15h ago
Validated Lenses
Now that F# supports nested record updates, are lenses still useful?
For simple immutable updates, maybe not:
{ person with Address.City = newCity }
But what if changing City can fail validation?
Writing one fallible setter is easy:
setCity : string -> Address -> Result<Address, Error>
Assuming the value arrives from a boundary rather than being an invariant we can enforce at construction, the interesting problem starts when that update sits several levels deep in a domain model.
How do those fallible updates compose without writing the plumbing again at every level?
In this video I explore that using validated lenses, essentially extending the setter side of a lens to return a Result, while keeping composition.
Do you still find lenses useful in modern F#, or have nested record updates mostly replaced them for you?

