Alex Rivera | Logout

scala either pattern match

Asked 2010-12-13T19:35:51.907
12

what is wrong in this piece of code?

(Left("aoeu")) match{case Right(x) => ; case Left(x) => }
<console>:6: error: constructor cannot be instantiated to expected type;
 found   : Right[A,B]
 required: Left[java.lang.String,Nothing]     

why the pattern matcher just doesn't skip the Right and examine Left?

Edit
Report

1 Answer

7
scala> val left: Either[String, String] = Left("foo")
left: Either[String,String] = Left(foo)

scala> left match {
     | case Right(x) => "right " + x
     | case Left(x) => "left " + x }
res3: java.lang.String = left foo
answered 2010-12-13T19:50:35.160

Your Answer