Created
June 28, 2016 14:28
-
-
Save paulp/a311ab5d7161169258127258d33700f9 to your computer and use it in GitHub Desktop.
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 Bippy { | |
final class BippyExtractor(s: String) { | |
def get: Char = s(0) | |
def isEmpty = false | |
} | |
def unapply(s: String) = new BippyExtractor(s) | |
} | |
object Test { | |
def main(args: Array[String]): Unit = { | |
// prints: char, a | |
"abc" match { case Bippy(c) => println(c.getClass + ", " + c) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment