Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)
- someVal match {
- case WideLoad(_, _, _, d, _) => d ! SomeMessage(...)
- }
- someVal match {
- case WideLoad(d = dActor) => dActor ! SomeMessage(...)
- // ^---------- does not compile
- }
- object WideLoadActorRef {
- def unapply(wl: WideLoad): Option[ActorRef] = { Some(wl.d) }
- }
- someVal match {
- case WideLoadActorRef(d) => d ! someMessage
- }
- object WideLoadBnD {
- def unapplySeq(wl: WideLoad): Option[(Int,ActorRef)] = { Some((wl.b,wl.d)) }
- }
- someVal match {
- case WideLoadBnD(b, d) => d ! SomeMessage(b)
- }
- case class Foo(a:Int, b:Int, c:String, d:java.util.Date)
- def f(foo:Foo) = foo match {
- case fo:Foo if fo.c == "X" => println("found")
- case _ => println("arrgh!")
- }
- f(Foo(1,2,"C",new java.util.Date())) //--> arrgh!
- f(Foo(1,2,"X",new java.util.Date())) //--> found
- case class Bar(a: Int, b:String)
- case class Baz(c:java.util.Date, d:String)
- case class Foo(bar:Bar, baz:Baz)
- def f(foo:Foo) = foo match {
- case Foo(Bar(1,_),Baz(_,"X")) => println("found")
- case _ => println("arrgh!")
- }
- f(Foo(Bar(1,"c"),Baz(new java.util.Date, "X"))) //--> found
- f(Foo(Bar(1,"c"),Baz(new java.util.Date, "Y"))) //--> arrgh!
- case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)
- val someVal = WideLoad(...)
- someVal match {
- case w: WideLoad => w.d ! SomeMessage(...)
- }
Add Comment
Please, Sign In to add comment