title: Scala enumerations with Singleton objects as enumeration elements and a possibility to iterate over them?
body: <p>I already looked at the <a href="https://stackoverflow.com/questions/1321745/scala-doesnt-have-enums-what-to-use-instead-of-an-enum">Scala question about emulating Java's <code>enum</code></a> and <a href="https://stackoverflow.com/questions/1898932/case-classes-vs-enumerations-in-scala">case classes vs. Enumeration</a> but It seems too much effort for too less benefit.</p>
  
  <p>Basically I would like to have a <code>values</code> method returning all singleton objects of <code>DayOfWeek</code> without repeating myself a few times.</p>
  
  <p>This is how my code should look like:</p>
  
  <pre><code>object DayOfWeek extends MyEnum {
    object MONDAY extends DayOfWeek(1)
    object TUESDAY extends DayOfWeek(2)
    object WEDNESDAY extends DayOfWeek(3)
    object THURSDAY extends DayOfWeek(4)
    object FRIDAY extends DayOfWeek(5)
    object SATURDAY extends DayOfWeek(6)
    object SUNDAY extends DayOfWeek(7)
  }
  
  class DayOfWeek(ordinal: Int)
  </code></pre>
  
  <p>The method <code>values</code> should return something like if it had been written like this: </p>
  
  <pre><code>val values = Array(MONDAY, TUESDAY, WEDNESDAY, THURSDAY,
                     FRIDAY, SATURDAY, SUNDAY)
  </code></pre>
  
  <p>Everything should happen in the <code>MyEnum</code> trait so I only need to extend it to get the functionality.</p>
  
  <pre><code>trait MyEnum {
    val values = this.getClass.getField("MODULE$") etc. etc.
  }
  </code></pre>
  
  <p>Any suggestion how this could be done exactly?
  The idea is that <code>values</code> accesses the class and finds all singleton objects of the class they are extending.</p>
  
  <p><strong>Edit: It looks like all suggestions don't take in account that the user can create objects too which should of course be comparable to the defined ones.</strong></p>
  
  <p>I'll try to give another example, maybe it is more clear:</p>
  
  <pre><code>object MonthDay extends MyEnum {
    //Some important holidays
    object NewYear       extends MonthDay( 1,  1)
    object UnityDay      extends MonthDay(11,  9)
    object SaintNicholas extends MonthDay(12,  6)
    object Christmas     extends MonthDay(12, 24)
  }
  
  class MonthDay(month: Int, day: Int)
  
  //Of course the user can create other MonthDays
  val myBirthDay = new MonthDay(month, day)
  
  if(!MonthDay.values.contains(myBirthDay)) "Well, I probably have to work"
  else "Great, it is a holiday!"
  </code></pre>
  
  <p>I want to have a trait (<code>MyEnum</code>) which I can mix into the object holding my "enumeration objects" with methods to return a list of them (<code>def values: List[MonthDay]</code>) or iterate over them (<code>def next: MonthDay</code> or <code>def previous: MonthDay</code>).</p>
  
  <p><strong>PPS: <a href="https://stackoverflow.com/questions/4239594/how-to-access-objects-within-an-object-by-mixing-in-a-trait-with-reflection">I created a new question for the second part of this question</a></strong> as requested by Ken Bloom.</p>