[Issue 596] Support array, arrayliteral and struct in switch and case
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 19 16:22:09 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #9 from bearophile_hugs at eml.cc 2013-02-19 16:22:06 PST ---
To match classes Scala uses the standard method "unapply":
http://www.scala-lang.org/node/112
object Twice {
def apply(x: Int): Int = x * 2
def unapply(z: Int): Option[Int] = if (z%2 == 0) Some(z/2) else None
}
object TwiceTest extends Application {
val x = Twice(21)
x match { case Twice(n) => Console.println(n) } // prints 21
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list