Basic pattern matching in C# 6
Yota via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 15 09:41:48 PDT 2014
On Friday, 15 August 2014 at 10:03:39 UTC, bearophile wrote:
> A proposal for a basic pattern matching in C# 6:
>
> http://www.infoq.com/news/2014/08/Pattern-Matching
>
> But it's still rather limited:
>
>>Under the current draft specification, there is no support for
>>range checks. This means you cannot write patterns such as “a
>>is Location( > 0, 1 to 5, <= 10)”. Nor is there support for
>>matching elements in a list or enumeration.<
>
> Bye,
> bearophile
If I'm not mistaken, you could do this.
public static class GreaterThan {
public static bool operator is(int val, int test) {
return val > test;
}
}
and then...
case Location(GreaterThan(0), BetweenInclusive(1, 5),
LessOrEqualTo(10)):
Though we should eventually be able to do something like the
following:
case Location(var x, var y, var z)
when (x > 0 && y >= 1 && y <= 5 && z <= 10):
More information about the Digitalmars-d
mailing list