title: Getting previous and next element of a value in a Scala enumeration
body: <p>I would like to add two new operations to a Scala <a href="http://www.scala-lang.org/api/2.10.3/index.html#scala.Enumeration" rel="nofollow">Enumeration</a> to get the previous and the next value given a certain value if it exists. For example, I would like to write something like:</p>
  
  <pre class="lang-scala prettyprint-override"><code>object Nums extends MyNewEnumerationType {
    type Nums = Value
    val One,Two,Three = Value
  }
  
  Nums.nextOf(One) // Some(Two)
  Nums.prevOf(One) // None
  </code></pre>
  
  <p>My idea was to create a new class and add the methods in this way:</p>
  
  <pre class="lang-scala prettyprint-override"><code>class PrevNextEnum extends Enumeration {
  
    val prevOf = values.zip(None +: values.map{_.some}.toSeq).toMap
    val nextOf = {
      if (values.isEmpty) Map.empty
      else values.zip(values.tail.map{_.some}.toSeq :+ None).toMap
    }
  
  }
  </code></pre>
  
  <p>The problem is that this doesn't work because when <code>prevOf</code> and <code>nextOf</code> are initialized, <code>values</code> is empty.</p>
  
  <p>First question: why <code>values</code> is empty and when it is filled with the values?</p>
  
  <p>Second question: how can I implement <code>prevOf</code> and <code>nextOf</code>?</p>
  
  <p>Third question: is it possible to add the methods <code>prevOf</code> and <code>nextOf</code> to the value type instead of the enumeration? Writing <code>One.next</code> feels more natural than writing <code>Num.nextOf(One)</code></p>