Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. case object & {
  2. def unapply[T](t : T) = Some(t, t)
  3. }
  4.  
  5.  
  6. case object ParamA {
  7. def unapply(jsonStr: String) : Option[String] = {
  8. // If param A found in json return a Some(...) else None
  9. ???
  10. }
  11. }
  12. case object ParamB {
  13. def unapply(jsonStr: String) : Option[String] = {
  14. // If param B found in json return a Some(...) else None
  15. ???
  16. }
  17. }
  18. case object ParamC {
  19. def unapply(jsonStr: String) : Option[String] = {
  20. // If param C found in json return a Some(...) else None
  21. ???
  22. }
  23. }
  24.  
  25. val jsonStr = "..." // A Json string
  26. jsonStr match {
  27. case ParamA(a) & ParamB(b) => {
  28. // Got a and b. Now do something with it
  29. }
  30. case _ => {
  31.  
  32. }
  33. }
  34.  
  35. val jsonStr = "..." // A Json string
  36. jsonStr match {
  37. case ParamA(a) & ParamB(b) & Optional(ParamC(c)) /* Is this possible? */ => {
  38. // Got a and b and an optional c. Now do something with it
  39. }
  40. case _ => {
  41.  
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement