Created
December 31, 2014 08:33
-
-
Save chemikadze/6bf44d676a0e302f724b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class Scalar(s: String) | |
scala> case class Sequence(s: Seq[String]) | |
scala> object ScalarMatcher { def unapply(x: Scalar) = Some(x.s) } | |
scala> object SequenceMatcher { def unapply(x: Sequence) = Some(x.s) } | |
scala> Scalar("x").s match { case ScalarMatcher(x) => x ; case _ => "because fuck you" } | |
<console>:11: error: scrutinee is incompatible with pattern type; | |
found : Scalar | |
required: String | |
Scalar("x").s match { case ScalarMatcher(x) => x ; case _ => "because fuck you" } | |
^ | |
scala> Sequence(Seq("x")).s match { case SequenceMatcher(x) => x ; case _ => "because fuck you" } | |
res6: Object = because fuck you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment