title: How to improve this scala code which is checking if two byte arrays are same?
body: <p>I have a method to compare two byte arrays. The code is java-style, and there are many "if-else"s.</p>
  
  <pre><code>def assertArray(b1: Array[Byte], b2: Array[Byte]) {
    if (b1 == null &amp;&amp; b2 == null) return;
    else if (b1 != null &amp;&amp; b2 != null) {
      if (b1.length != b2.length) throw new AssertionError("b1.length != b2.length")
      else {
        for (i &lt;- b1.indices) {
          if (b1(i) != b2(i)) throw new AssertionError("b1(%d) != b2(%d)".format(i, i))
        }
      }
    } else {
      throw new AssertionError("b1 is null while b2 is not, vice versa")
    }
  }
  </code></pre>
  
  <p>I have tried as following, but it's not simplified the code much:</p>
  
  <pre><code>(Option(b1), Option(b2)) match {
      case (Some(b1), Some(b2)) =&gt; if ( b1.length == b2.length ) {
         for (i &lt;- b1.indices) {
          if (b1(i) != b2(i)) throw new AssertionError("b1(%d) != b2(%d)".format(i, i))
         }
      } else {
         throw new AssertionError("b1.length != b2.length")
      }
      case (None, None) =&gt; _
      case _ =&gt; throw new AssertionError("b1 is null while b2 is not, vice versa")
  }
  </code></pre>