Coding StandardsFunctional Patterns, Results, and Errors
Functional Patterns, Results, and Errors
Composing behaviour and handling expected failure functionally instead of with exceptions and mutable state.
These standards cover representing expected failure as a value (Result/Option) instead of
exceptions, composing behaviour with delegates and higher-order functions instead of class
hierarchies, and working correctly with closures, iterators, and immutable collections. Apply
them whenever a method's failure is expected and recoverable, or when composing behaviour that
would otherwise become a class hierarchy.
- Build Functional Types from Smart Constructors and Closed Unions
- Chain Async Operations Through Result
- Compose Result Values with Map/Bind/And/MapError
- Exceptions Are Dynamically Scoped
- Expose Immutable State via Persistent Collections
- Fast Immutable Design
- Implement GoF Patterns as Delegates and Higher-Order Functions
- Prefer Result Types Over Exceptions for Expected Failures
- The Option Type Instead of Nullable Reference Chains
- Understand Closures Capture Variables by Reference
- Use a
Result<T, TError>Type for Expected Failures - Write Iterator Methods with yield return