Recap
Union types: Option
and Result
Option
and Result
What they are used for:
Model absence of value and business errors
Partial operations made total
tryXxx
Smart constructor
tryCreate
How to use them:
Chaining:
map
,bind
,filter
→ ROPPattern matching
Their benefits:
null
free,Exception
free → no guard clauses Cluttering the codeMakes business logic and happy path more readable
Computation expression (CE)
Syntactic sugar: inner syntax standard or "banged" (
let!
)Separation of Concerns: business logic vs "machinery"
Compiler translates to builder calls
Object storing a state
Builds an output value of a specific type
Can be nested but not easy to combine!
Underlying theoretical concepts
Monoid →
seq
(of composable elements and with a "zero ")Monad →
async
,option
,result
Applicative →
validation
/Result<'T, 'Err list>
Libraries: FSharpPlus, FsToolkit, Expecto, Farmer, Saturn, Bolero...
🔗 Additional ressources
Compositional IT (Isaac Abraham)
F# for Fun and Profit (Scott Wlaschin)
Extending F# through Computation Expressions
Last updated
Was this helpful?