title: Pattern Matching on Either
body: <p>From <a href="http://www.manning.com/bjarnason/" rel="nofollow">Functional Programming in Scala</a>, I'm trying to implement <code>Either.map</code>.</p>
  
  <pre><code>trait Either[+E, +A] {
      def map[B](f: A =&gt; B): Either[E, B] =  this match {
          case Either(x: E, y: A) =&gt; Right(f(y))
          case _ =&gt; Left()
      }
  }
  </code></pre>
  
  <p>One error shows up on compilation, among others. I'm not showing them since I appear to be missing the concept of implementing <code>Either.</code></p>
  
  <pre><code>    Either.scala:3: error: value Either is not a case class constructor, 
  nor does it have an unapply/unapplySeq method
                      case Either(x: E, y: A) =&gt; Right(f(y))
  </code></pre>
  
  <p>Please advise me on implementing it.</p>