title: if else in map function in scala
body: <p>I'm new to Scala and spark,  I have tried below code but it is not working. Can anyone help me (in Scala only not Data-frames) to solve it. After this I have to do a few more transformations</p>
  
  <p>Code : </p>
  
  <pre><code>val file = sc.textFile("winners.csv")
  file.map(_.split(",")).map{x=&gt;if(x(0)==x(2)) x(1) else if(x(1)==x(2)) x(0), x(2)}
  </code></pre>
  
  <p><strong>Input</strong>:
  Team_1, Team_2 ,<strong>winner</strong></p>
  
  <p>Team_A, Team_B, Team_B</p>
  
  <p>Team_C, Team_D, Team_C</p>
  
  <p>Team_B, Team_C, Team_B</p>
  
  <p>Team_A, Team_D, Team_A</p>
  
  <p>Team_D, Team_B, <strong>Tie</strong></p>
  
  <p><strong>Output</strong>:</p>
  
  <p>Looser, Winner</p>
  
  <p>Team_A, Team_B</p>
  
  <p>Team_D, Team_C</p>
  
  <p>Team_C, Team_B</p>
  
  <p>Team_D, Team_A</p>
  
  <p>Tied match is not required</p>