Implement Compare trait for @list.List with lexicographic order #2772
+70
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the missing
Comparetrait for@list.List, addressing the consistency issue where@immut/list.Listhad Compare support but@list.Listdid not.Changes
Added Compare implementation: Implements lexicographic comparison for
@list.Listwhere elements are compared pairwise until a difference is found. When all shared elements are equal, the shorter list is considered less than the longer one.Added comprehensive tests: Includes test cases covering lexicographic comparison, length-based comparison when prefixes are equal, equality comparison, and empty list edge cases.
Updated interface: The
pkg.generated.mbtifile now exposesimpl[A : Compare] Compare for List[A]in the public API.Implementation Details
The implementation follows lexicographic order semantics as clarified in the issue discussion:
This provides consistency with other data structures in the standard library and enables
@list.Listto be used in contexts requiring total ordering, such as sorted collections.Fixes #[issue_number]
Original prompt
Fixes #2757
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.