Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "any" option to tuple matching #8

Closed
DavidArno opened this issue Sep 16, 2016 · 3 comments
Closed

Add "any" option to tuple matching #8

DavidArno opened this issue Sep 16, 2016 · 3 comments

Comments

@DavidArno
Copy link
Owner

DavidArno commented Sep 16, 2016

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
Copy link
Owner Author

DavidArno commented Dec 2, 2016

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
Copy link
Owner Author

DavidArno commented Feb 1, 2017

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 DavidArno added this to the V2.3.0 milestone Feb 2, 2017
DavidArno added a commit that referenced this issue Feb 2, 2017
Added complete support for any/__ to Tuple<,> and Tuple<,,> pattern matchers.
DavidArno added a commit that referenced this issue Feb 2, 2017
* Moved Either<,> to Unions, where it should have been in the first place. Treating this as a non-breaking change as it's an undocumented partial addition to v2.2.0.

* Changed the way "any" matches are constructed for tuples. This now relies on parameters of With and Or being Either<T,Any> and the Either<,> type supporting implicit conversions from T and Any to Either<T,Any>. This removed the need to add just shy of 100 new methods to the three matcher classes used by tuple matching, plus to the interfaces and 25 or so to the tuple creation class etc.

* As mentioned above, the Either<T1,T2> type now supports implicit conversions from T1 and T2.

Added a bunch more tests for "nay matching" on tuples. This feature now appears to be complete.
@DavidArno
Copy link
Owner Author

v2.3.0 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant