Created
September 15, 2016 12:56
-
-
Save bbarker/b1164c15f9a9d0330651dd5fe37fe43a to your computer and use it in GitHub Desktop.
Showing that you need to remember to add the None case to your extractor
This file contains hidden or 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
object ExtTest { | |
def unapply(arg: Int): Option[Int] = arg match { | |
case a if a < 5 => Some(a) | |
} | |
} | |
val x = 3 | |
x match { | |
case ExtTest(a) => println(a) | |
} | |
val y = 10 | |
y match { | |
case ExtTest(a) => println(a) | |
// This will result in a MatchError | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At least, you need to appropriately generate None, whether or not it is through a case clause.