title: Scala - How can I split an array of integers into tuples of 2 elements (coordinates)?
body: <p>I'm pretty new here so I'm not if I put this in the right section. I'm also very new to Scala.</p>
  
  <p>Anyways, so I'm trying to read numbers from a text file (I guess they're strings here) and split them into pairs, in the order they are read but I'm having trouble dealing with:</p>
  
  <ul>
  <li>new lines</li>
  <li>splitting an array of numbers to pairs</li>
  </ul>
  
  <p>Here's my code:</p>
  
  <pre><code>def main(args: Array[String]): Unit = {
    val file = Source.fromFile("/Users/donatkapesa/Desktop/poly.txt")
    val fileLines = file.getLines()
  
    while(fileLines.hasNext &amp;&amp; !fileLines.isEmpty) {
      val array = fileLines.next.split(" ")
      //this doesn't take care of new lines. I have tried .split(" +") and .split("\\s+")
  
      // change the array elements to integers
      val intArray = array.map(array =&gt; array.toInt)
  
      // split array elements into tuples. But it doesn't work
      val coordinates = intArray.map(case Array(x,y) =&gt; (x,y))
    }
  </code></pre>