-
-
Notifications
You must be signed in to change notification settings - Fork 76
Refactor Min/Max methods with better selector and comparer overload support #187
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
Conversation
…parate Comparer Variants
|
Is this another breaking change? 🤔 I can't seem to find this |
|
Thanks for asking. Yes, this is a breaking change—the return type of Max/Min has changed from T to R, where R is the type returned by the selector function, Max/Min replicate the behavior of the Max/Min overload wtih selector argument. The WithComparer variants are introduced to replicate the overload behavior of Max/Min overload with Comparer argument. However, due to TypeScript's lack of true function overloading, I had to use different function names. |
…ect comparator functions
|
I will take further look the coming days to make further reviews and improvements, no hurry. |
|
I'd like to know the opinion of @typescriptbob on this (if he is still around) as another data point since he is also a C# fellow (AFAIK) 😉 |
|
Hi @kutyel, I have removed the *WithComparer Variants and re-implemented the Min and Max functions with function overloading. Max function overloads Max function implementation Min function overloads Min function implementation In the implementation, the length of the comparerOrSelector function is inspected to determine the type of the function delegate received, length=1 if it is a selector, length=2 if it is a comparer. Another enhancement is to use elements.reduce instead of a custom foreach loop to get the max/min values |
Awesome! I saw you were able to use TypeScript's overload syntax to make it work, nice! 👏🏻 However, I'm a bit concerned about the usage of @ts-ignore in the codebase, it is generally not a good sign, what is the exact type error? |
|
Earlier today, there was a build error that I temporarily bypassed using @ts-ignore in the test case. |
|
🎉 This PR is included in version 3.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Refactor
Min/MaxMethods to Support Generic Selector Overloads and Separate Comparer VariantsThis pull request refactors the
MinandMaxmethods to provide greater flexibility through generic selector overloads, and separates the comparer-based logic into clearly named methods.Changes