title: How to order a list of tuples of integers in Scala
body: <p>Given a list of tuples of integers:</p>
  <pre><code>List[(Int, Int, Int)] =  List((2,1,3), (4,2,6),...)
  </code></pre>
  <p>I'd like to sort them by their third component but if two tuples have the same third component then I'd like to order them by their second component. For instance, I'd like (6,3,9) &lt; (4,7,9). Here is what I tried:</p>
  <pre><code>     def order(k: List[(Int, Int, Int)]) = {
          var t = List[Int]()
          if (k.map(_._3) == t) {
              k.sortBy(_._2)
              t = k.map(_._3)
              k
          } else {
              k.sortBy(_._3)
              t = k.map(_._3)
              k
          }   
       }
  </code></pre>
  <p>Thank you in advance!</p>