-
Notifications
You must be signed in to change notification settings - Fork 12
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pattern Matching #59
Pattern Matching #59
Conversation
Codecov Report
@@ Coverage Diff @@
## master #59 +/- ##
============================================
+ Coverage 93.54% 94.30% +0.76%
- Complexity 431 463 +32
============================================
Files 31 48 +17
Lines 899 984 +85
============================================
+ Hits 841 928 +87
+ Misses 58 56 -2
Continue to review full report at Codecov.
|
Thanks. I appreciate the work. So I wonder what would that get us? Are there any cases where munus would give something better? |
What do you think about more functional way (with functions for shorter notations): $result = matchValue(1)->of(case(isNotNull(), 'match'), case('other')); That code at the top could actually produce what's at the bottom. Such syntactic sugar 馃槈 $result = GenericMatch::value(1)->of(
GenericCase::of(Is::notNull(), 'match'),
DefaultCase::of('other')
); |
Yeah, the functional way looks very nice. How do you think to do that? Just wrap the existing classes into functions?
I thought only about the older version of PHP, the native PHP8 match is the best option I think. |
Will happily merge this pull request, even if native support is better. |
It looks much better than using static functions munusphp#59 (comment)
Great! 馃槃 |
It turned out really elegant. 馃憦 馃憤 |
Here is my proposition for pattern matching 馃槂
Unfortunately, the "case", and "match" (the "match" since PHP8.0) are reserved words, so I used the "Generic" prefix, but I'm not sure if this is ok.
I added a new ignore statement to PHPStan. I have no idea where is the problem, everything looks ok, especially that this part was not changed by me 馃 .