Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case object & {
- def unapply[T](t : T) = Some(t, t)
- }
- case object ParamA {
- def unapply(jsonStr: String) : Option[String] = {
- // If param A found in json return a Some(...) else None
- ???
- }
- }
- case object ParamB {
- def unapply(jsonStr: String) : Option[String] = {
- // If param B found in json return a Some(...) else None
- ???
- }
- }
- case object ParamC {
- def unapply(jsonStr: String) : Option[String] = {
- // If param C found in json return a Some(...) else None
- ???
- }
- }
- val jsonStr = "..." // A Json string
- jsonStr match {
- case ParamA(a) & ParamB(b) => {
- // Got a and b. Now do something with it
- }
- case _ => {
- }
- }
- val jsonStr = "..." // A Json string
- jsonStr match {
- case ParamA(a) & ParamB(b) & Optional(ParamC(c)) /* Is this possible? */ => {
- // Got a and b and an optional c. Now do something with it
- }
- case _ => {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement