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

Make indexedEnum comparable #10

Closed
pedrorijo91 opened this Issue Dec 3, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@pedrorijo91

pedrorijo91 commented Dec 3, 2016

Since indexedEnums have an index, it should be easy to sort them. Maybe by adding extends Ordered[] and defining the .compare method using the index value?

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Dec 7, 2016

Contributor

IndexedEnum is parametrised over an unconstrained type T for the index and T is not necessarily T : Ordered (it could be a custom type without natural ordering), so I would avoid forcing Ordered onto all ItemizedIndices.
Do you have an explicit use case for this? If so, we can take a look at how to do this cleanly.

Contributor

utaal commented Dec 7, 2016

IndexedEnum is parametrised over an unconstrained type T for the index and T is not necessarily T : Ordered (it could be a custom type without natural ordering), so I would avoid forcing Ordered onto all ItemizedIndices.
Do you have an explicit use case for this? If so, we can take a look at how to do this cleanly.

@pedrorijo91

This comment has been minimized.

Show comment
Hide comment
@pedrorijo91

pedrorijo91 Dec 7, 2016

I've been comparing some approaches for enumerations in scala and I've found this 'feature' that I could not find an easy way to make it work with itemized.

While it's not a very common use case, it may happen. If you wish to leave the issue here until someone else complains feel free (or to close until someone reopens it).

pedrorijo91 commented Dec 7, 2016

I've been comparing some approaches for enumerations in scala and I've found this 'feature' that I could not find an easy way to make it work with itemized.

While it's not a very common use case, it may happen. If you wish to leave the issue here until someone else complains feel free (or to close until someone reopens it).

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Dec 7, 2016

Contributor

I'd be interested in seeing how others deal with this, do you have a link to a library that supports Order?

Contributor

utaal commented Dec 7, 2016

I'd be interested in seeing how others deal with this, do you have a link to a library that supports Order?

@pedrorijo91

This comment has been minimized.

Show comment
Hide comment
@pedrorijo91

pedrorijo91 Dec 7, 2016

for instance, enumeratum, does not supports Order itself, but it's implementation doesn't block easy workarounds:

sealed abstract class Weekday(val order: Int) extends EnumEntry with Ordered[Weekday] {
   def compare(that: Weekday) = this.order - that.order
 }

 object Weekday extends Enum[Weekday] {
   val values = findValues

   case object Monday extends Weekday(2)
   case object Tuesday extends Weekday(3)
   case object Wednesday extends Weekday(4)
   case object Thursday extends Weekday(5)
   case object Friday extends Weekday(6)
   case object Saturday extends Weekday(7)
   case object Sunday extends Weekday(1)
 }

this is somehow related with #11

pedrorijo91 commented Dec 7, 2016

for instance, enumeratum, does not supports Order itself, but it's implementation doesn't block easy workarounds:

sealed abstract class Weekday(val order: Int) extends EnumEntry with Ordered[Weekday] {
   def compare(that: Weekday) = this.order - that.order
 }

 object Weekday extends Enum[Weekday] {
   val values = findValues

   case object Monday extends Weekday(2)
   case object Tuesday extends Weekday(3)
   case object Wednesday extends Weekday(4)
   case object Thursday extends Weekday(5)
   case object Friday extends Weekday(6)
   case object Saturday extends Weekday(7)
   case object Sunday extends Weekday(1)
 }

this is somehow related with #11

@utaal utaal closed this Jul 10, 2018

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