diff options
author | Paul Phillips <paulp@improving.org> | 2013-08-18 15:14:47 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-08-18 15:20:20 -0700 |
commit | b3d9dfa9857aeb937a987536b3e2029d3be0030b (patch) | |
tree | 30b2f9b9777eb3df2622d92daf572e7000654a54 /test/files/run/string-extractor.scala | |
parent | 6d77da374e94ea8b80fc0bf9e544e11f4e9d5cc8 (diff) | |
download | scala-b3d9dfa9857aeb937a987536b3e2029d3be0030b.tar.gz scala-b3d9dfa9857aeb937a987536b3e2029d3be0030b.tar.bz2 scala-b3d9dfa9857aeb937a987536b3e2029d3be0030b.zip |
An unapplySeq-via-String test.
There are a lot of details yet to be ironed out when it comes
to sequences, but at least here's a little evidence that the basic
mechanisms work.
Diffstat (limited to 'test/files/run/string-extractor.scala')
-rw-r--r-- | test/files/run/string-extractor.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/files/run/string-extractor.scala b/test/files/run/string-extractor.scala new file mode 100644 index 0000000000..4fb977df0b --- /dev/null +++ b/test/files/run/string-extractor.scala @@ -0,0 +1,30 @@ +final class StringExtract(val s: String) extends AnyVal { + def isEmpty = (s eq null) || (s == "") + def get = this + def length = s.length + def lengthCompare(n: Int) = s.length compare n + def apply(idx: Int): Char = s charAt idx + def head: Char = s charAt 0 + def tail: String = s drop 1 + def drop(n: Int): StringExtract = new StringExtract(s drop n) + + override def toString = s +} + +object Bippy { + def unapplySeq(x: Any): StringExtract = new StringExtract("" + x) +} + +object Test { + def f(x: Any) = x match { + case Bippy('B' | 'b', 'O' | 'o', 'B' | 'b', xs @ _*) => xs + case _ => "nope" + } + + def main(args: Array[String]): Unit = { + println(f("Bobby")) + println(f("BOBBY")) + println(f("BoBoTheClown")) + println(f("TomTomTheClown")) + } +} |