-
Notifications
You must be signed in to change notification settings - Fork 3
Make indexedEnum comparable #10
Comments
|
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). |
I'd be interested in seeing how others deal with this, do you have a link to a library that supports |
for instance, enumeratum, does not supports 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 |
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?The text was updated successfully, but these errors were encountered: