Create logic functions combining patterns to achieve a more granular matching.
Complex conditions are no match for Myra.
Apart from checking a single pattern each time, Myra allows to compose patterns with logic operators. In such a case, the action will only execute if the resulting logic function is true.
These are the available logic combinators:
Is true if both patterns are true.
Input A | Input B | Output |
---|---|---|
false | false | false |
false | true | false |
true | false | false |
true | true | true |
Is true if one or both patterns are true.
Input A | Input B | Output |
---|---|---|
false | false | false |
false | true | true |
true | false | true |
true | true | true |
Is true if the pattern is false.
Input | Output |
---|---|
false | true |
true | false |
Is true if both patterns have a different value.
Input A | Input B | Output |
---|---|---|
false | false | false |
false | true | true |
true | false | true |
true | true | false |
Is true if both patterns have the same value.
Input A | Input B | Output |
---|---|---|
false | false | true |
false | true | false |
true | false | false |
true | true | true |
These combinators can be used like this:
person.Age.Match(Patterns.IsGreaterOrEqual(18) .And(Patterns.IsLesserThan(30)), p => Console.WriteLine("Person is within age range.")); dog.Match(isHusky.Not(), d => Console.WriteLine($"{d.Name} isn't a husky."));
By combining the provided operations, it is possible to express any function, like:
In fact, the default Xnor function is actually implemented combining basic operations: