Guest User

Untitled

a guest
Nov 13th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)
  2.  
  3. someVal match {
  4. case WideLoad(_, _, _, d, _) => d ! SomeMessage(...)
  5. }
  6.  
  7. someVal match {
  8. case WideLoad(d = dActor) => dActor ! SomeMessage(...)
  9. // ^---------- does not compile
  10. }
  11.  
  12. object WideLoadActorRef {
  13. def unapply(wl: WideLoad): Option[ActorRef] = { Some(wl.d) }
  14. }
  15.  
  16. someVal match {
  17. case WideLoadActorRef(d) => d ! someMessage
  18. }
  19.  
  20. object WideLoadBnD {
  21. def unapplySeq(wl: WideLoad): Option[(Int,ActorRef)] = { Some((wl.b,wl.d)) }
  22. }
  23.  
  24. someVal match {
  25. case WideLoadBnD(b, d) => d ! SomeMessage(b)
  26. }
  27.  
  28. case class Foo(a:Int, b:Int, c:String, d:java.util.Date)
  29.  
  30. def f(foo:Foo) = foo match {
  31. case fo:Foo if fo.c == "X" => println("found")
  32. case _ => println("arrgh!")
  33. }
  34.  
  35. f(Foo(1,2,"C",new java.util.Date())) //--> arrgh!
  36. f(Foo(1,2,"X",new java.util.Date())) //--> found
  37.  
  38. case class Bar(a: Int, b:String)
  39. case class Baz(c:java.util.Date, d:String)
  40. case class Foo(bar:Bar, baz:Baz)
  41.  
  42. def f(foo:Foo) = foo match {
  43. case Foo(Bar(1,_),Baz(_,"X")) => println("found")
  44. case _ => println("arrgh!")
  45. }
  46.  
  47. f(Foo(Bar(1,"c"),Baz(new java.util.Date, "X"))) //--> found
  48. f(Foo(Bar(1,"c"),Baz(new java.util.Date, "Y"))) //--> arrgh!
  49.  
  50. case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)
  51.  
  52. val someVal = WideLoad(...)
  53.  
  54. someVal match {
  55. case w: WideLoad => w.d ! SomeMessage(...)
  56. }
Add Comment
Please, Sign In to add comment