title: Lots of nested match ... case in pattern matching
body: <p>I have an automatically generated client for an web service. I has many complicated classes and I have to do a pattern matching against it. For now I have a structure looking like this:</p>
  
  <pre><code>val response = client.getResponse
  response match {
    case Left(_) =&gt; None
    case Right(a: SomeClass) =&gt; a match {
  
      case SomeClass2(b: Option[SomeClass3]) =&gt; b match {
  
        case None =&gt; None
        case Some(c: SomeClass3) =&gt; c match {
  
          case SomeClass4(_, _, _, _, d: Seq[SomeClass4]) =&gt; d match {
            case Nil =&gt; None
  
            case seq: Seq[SomeClass5] =&gt; seq match {
              case Nil =&gt; None
              case Seq(xs@_*) =&gt; xs map { x =&gt;
                x match {
                  case Nil =&gt; None
  
                  case SomeClass6(e: SomeClass7) =&gt; e match {
                    case Nil =&gt; None
  
                     case SomeClass8(f, _, _, _, _) =&gt; f match {
                      case Nil =&gt; None
                      case Seq(xs@_*) =&gt; xs map { x =&gt; 
                        x match {
  
                          case Nil =&gt; None
                          case SomeClass9(g: Seq[SomeClass9], _, _, _, _, _, _, _, _, _, _) =&gt; /* + some nested levels more*/
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>where <code>SomeClass1 - SomeClass9</code> are <code>case</code> classes.</p>
  
  <p>As you can see, it seems frightening. What do I do about it? What's the standard way to make it look nicer?</p>
  
  <p>I guess there should be not only refactoring but rather another approach.</p>