Skip to content

Generic implementation of Max and Min functions.#186

Merged
kutyel merged 3 commits intokutyel:masterfrom
mobilebilly:feature/generic-max-min
Jul 21, 2025
Merged

Generic implementation of Max and Min functions.#186
kutyel merged 3 commits intokutyel:masterfrom
mobilebilly:feature/generic-max-min

Conversation

@mobilebilly
Copy link
Contributor

Summary

Supports number, string, and boolean types using built-in comparers.
For unsupported types, a custom comparer must be provided.

Details

This pull request is important and essential because it addresses a fundamental limitation in the existing implementation by removing the hardcoded assumption that all comparers return a number. By introducing support for built-in comparers for number, string, and boolean types—and requiring explicit custom comparers for other types—we significantly improve type safety, flexibility, and clarity in the API.

Additionally, the updated method signatures now better reflect the semantics of similar functionality in C#, aligning the design with established .NET practices. This not only enhances code readability and maintainability for developers familiar with LINQ-style patterns, but also lays a stronger foundation for future extensibility.

Breaking change:

The method signatures have been modified to avoid hardcoding the return type as number. The new design more closely aligns with the original implementation in C# and improves type flexibility.

From:

Max(selector?: (element: T, index: number) => number): number
Min(selector?: (element: T, index: number) => number): number

To:

Max(comparer?: (element: T) => number): T | undefined
Min(comparer?: (element: T) => number): T | undefined

Supports number, string, and boolean types using built-in comparers.
For unsupported types, a custom comparer must be provided.
@coveralls
Copy link

coveralls commented Jul 18, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling 56de1e7 on mobilebilly:feature/generic-max-min
into dbc501b on kutyel:master.

Copy link
Owner

@kutyel kutyel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

Thank you very much for you contribution, it looks really good and I'm happy to merge it as a major change if you address a couple of minor comments I have 😉

When merging this with a major commit message a new mayor release will be auto-released so no worry about the breaking changes.

Thanks for your effort and work you put into this! I especially appreciate the effort you made to make it closer to C#, this was the overall goal of this library after all! 👏🏻

@mobilebilly mobilebilly requested a review from kutyel July 18, 2025 17:02
Copy link
Owner

@kutyel kutyel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, huge thanks for you contribution! 🎉

@kutyel kutyel merged commit 83b9adb into kutyel:master Jul 21, 2025
1 check passed
@github-actions
Copy link

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants