-
Notifications
You must be signed in to change notification settings - Fork 15
PatternMatching
As of C# 8, the language itself now has excellent support for pattern matching. As such, the various types Succinc<T> have been updated to support property-based matching.
Support for Succinc<T>'s pattern matching features (excluding collection matching for now as C# 8 doesn't offer an equivalent) will likely be removed in a future version, but for now they continue to be provided for developers who've not yet switched to C# 8.
One significant difference between Succinc<T>'s pattern matching and C#'s switch expression is what happens when a case isn't covered. C# will give you a compiler warning. Succinc<T> can't do this and so instead will throw a NoMatchException if no match is made when evaluated at runtime.
This pattern matching guide is split into the following sections:
- Pattern matching on collections.
- Pattern matching on discriminated unions.
-
Pattern matching on
Either<TLeft, TRight>. - Pattern matching on
Option<T> - Pattern matching on
Success<T> - Pattern matching on tuples
- Pattern matching on
ValueOrErrorandValueOrError<TValue, TError> - Type-based pattern matching for all other types
- Value-based pattern matching on all other types
Action/FuncconversionsCyclemethods- Converting between
ActionandFunc - Extension methods for existing types that use
Option<T> - Indexed enumerations
IEnumerable<T>cons- Option-based parsers
- Partial function applications
- Pattern matching
- Pipe Operators
- Typed lambdas
AnyEither<TLeft,TRight>NoneOption<T>Success<T>Union<T1,T2>Union<T1,T2,T3>Union<T1,T2,T3,T4>UnitValueOrError