title: How to declare tuple as the return type of a function and how to access tuple in caller code in scala?
body: <p>Suppose I have a scala function that is supposed to return a tuple of type
  <code>(String, Int, Int) mapped to keys (words, row, col)</code>:</p>
  
  <pre><code>def getResult(param: Int)    {
  
  // a lot of logic goes here to generate tuple values
  
  // now return the tuple
  
  }
  </code></pre>
  
  <p>In caller code:</p>
  
  <pre><code>var words, row, col
  if(someValue) {
  
    getResults(someValue)  // assigns the tuple values to keys words, row and col
    // reference words, row and col variables here
  
  } else
    getResults(someOtherValue)  // assigns the tuple values to keys words, row and col
  // reference words, row and col variables here
  }
  // in this scope here words, row and col are defined  and must have values that got assigned in above code
  // do something more with words, row and col variables.
  </code></pre>
  
  <p>The code is incomplete. So how would I declare and return the tuple in the function and how would I use in above scenario?</p>
  
  <p>Is tuple recommended way in above case even though map seems better fit?</p>
  
  <p>Despite all the answers I got, no answer has addressed the issue of how do I declare tuple and fill the tuple later in the code ( not assigning values to tuple at the time declaration like this answer suggests: </p>
  
  <pre><code>var (words, row, col) =  if(someValue) {
    getResults(someValue)
  } else {
    getResults(someOtherValue)
  }
  </code></pre>
  
  <p>This is the part of the code that remains unanswered:</p>
  
  <pre><code>var words, row, col  // how do I delcare tuple here?
      if(someValue) {
  
        getResults(someValue)  // assigns the tuple values to keys words, row and col
               // how I do that here ?
        // reference words, row and col variables here
  
      } else
        getResults(someOtherValue)  // assigns the tuple values to keys words, row and col
      // reference words, row and col variables here
      }
  </code></pre>