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

[Feature Request] Introduce Ordering trait #2462

Closed
1 task done
jayzhan211 opened this issue May 2, 2024 · 3 comments
Closed
1 task done

[Feature Request] Introduce Ordering trait #2462

jayzhan211 opened this issue May 2, 2024 · 3 comments
Labels
enhancement New feature or request mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library

Comments

@jayzhan211
Copy link
Contributor

Review Mojo's priorities

What is your request?

We have EqualityComparable trait for eq and ne.

But, that is not enough to implement comparison function, like sorting

I think we need to introduce trait like

trait OrderingComparable:
  fn __lt__():  1 < 2
  fn __gt__(): 2 > 1
  fn __le__():  1 <= 2
  fn __ge__(): 2 >= 1

There might be a better name for OrderingComparable.

What is your motivation for this change?

Having trait for comparison function

Any other details?

No response

@jayzhan211 jayzhan211 added enhancement New feature or request mojo-repo Tag all issues with this label labels May 2, 2024
@JoeLoser JoeLoser added the mojo-stdlib Tag for issues related to standard library label May 3, 2024
@JoeLoser
Copy link
Collaborator

JoeLoser commented May 3, 2024

I agree we want this; I haven't thought much about the naming yet. This will enable us to write a generic sorting function and start on algorithms and the like. Did you have a specific use case in mind in applying this in the library or is this just a "known nice to have/something that is needed" from your perspective?

@jayzhan211
Copy link
Contributor Author

I think it is what we need for List sorting.

#2390

@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 7, 2024 — with Linear
Copy link
Collaborator

We have a Comparable trait now that serves this purpose. We may rename it to PartialOrd or something, but it's functionally fine for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library
Projects
None yet
Development

No branches or pull requests

3 participants