DavidArno / SuccincT

Discriminated unions, pattern matching and partial applications for C#
MIT License
266 stars 15 forks source link

Add "any" option to tuple matching #8

Closed DavidArno closed 7 years ago

DavidArno commented 7 years ago

Currently, if we have a tuple, (x, y), which we want to match on, and we are only interested in testing x, a Where must be used:

var result = someTuple.Match().To<bool>()
                      .Where((x, y) => x == 1).Do(true)
                      .Else().Do(false);

Add support for an Any type (which exposes a value singleton, _), that can be used with With:

var result = someTuple.Match().To<bool>()
                      .With(1, _).Do(true)
                      .Else().Do(false);
DavidArno commented 7 years ago

This work is currently on hold due to "discards" being added to C# 7 (see Proposed changes for deconstruction, declaration expressions, and discards, which could affect the way this feature would work.

DavidArno commented 7 years ago

Discards are happening in C# 7. This would have the unfortunate affect of any static import of the Any type (to enable the use of its _ construct) of then putting a _ value in scope and thus preventing the use of discards.

So I shall change the _ to any (and an alternative __) for this feature and continue working on it.

DavidArno commented 7 years ago

v2.3.0 released.