3 ms·
I use Option<T> types very happily in C# without sum types. Most of what would be pattern matching can be done with just methods. Car c = maybeCar.GetValue
by alkonaut 6y ago
I use Option<T> types very happily in C# without sum types. Most of what would be pattern matching can be done with just methods.
Car c = maybeCar.GetValueOr(CreateCar()) // inline fallback
maybeDog.Do(d => b.Bark()) // only performs call if present
Sailboat s = mybeBoat.As<SailBoat>() // none unless of correct subtype
And so on.
With nullable reference types C# now has a builtin alternative to this, but it has worked we’ll for many years.