title: scala: from seq to tuple
body: <p>It is very easy to convert a tuple into a List/Seq by doing:</p>
  
  <p><code>myTuple.productIterator.toSeq</code></p>
  
  <p>But what about the reverse operation (just out of curiosity). The code below works, but is quite ugly...</p>
  
  <pre><code>def arrayToTuple(a: Seq[Any]) = a.size match {
      case  1 =&gt; (a(0))
      case  2 =&gt; (a(0), a(1))
      case  3 =&gt; (a(0), a(1), a(2))
      case  4 =&gt; (a(0), a(1), a(2), a(3))
      case  5 =&gt; (a(0), a(1), a(2), a(3), a(4))
      case  6 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5))
      case  7 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6))
      case  8 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7))
      case  9 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8))
      case 10 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9))
      case 11 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10))
      case 12 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11))
      case 13 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12))
      case 14 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13))
      case 15 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14))
      case 16 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15))
      case 17 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15), a(16))
      case 18 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15), a(16), a(17))
      case 19 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15), a(16), a(17), a(18))
      case 20 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15), a(16), a(17), a(18), a(19))
      case 21 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15), a(16), a(17), a(18), a(19), a(20))
      case 22 =&gt; (a(0), a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10), a(11), a(12), a(13), a(14), a(15), a(16), a(17), a(18), a(19), a(20), a(21))
      case  _ =&gt; (0)
    }
  </code></pre>