Skip to content

Instantly share code, notes, and snippets.

@paulp
Created June 28, 2016 14:28
Show Gist options
  • Save paulp/a311ab5d7161169258127258d33700f9 to your computer and use it in GitHub Desktop.
Save paulp/a311ab5d7161169258127258d33700f9 to your computer and use it in GitHub Desktop.
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