title: Transforming a scala list based on condition
body: <p>I have a sorted list of tuples (sorted by last element which is linenumber)</p>
  
  <pre><code>val x = List(
              ("taskENTER_CRITICAL", 1443),
              ("taskEXIT_CRITICAL", 1492),
              ("taskEXIT_CRITICAL", 1510),
              ("taskEXIT_CRITICAL", 1528),
              ("taskENTER_CRITICAL", 1551),
              ("taskEXIT_CRITICAL", 1555),
              ("taskENTER_CRITICAL", 1602),
              ("taskEXIT_CRITICAL", 1614)
            )
  </code></pre>
  
  <p>I need to transform this into </p>
  
  <pre><code> ("taskENTER_CRITICAL", 1443),
   ("taskEXIT_CRITICAL", 1528),
   ("taskENTER_CRITICAL", 1551),
   ("taskEXIT_CRITICAL", 1555),
   ("taskENTER_CRITICAL", 1602),
   ("taskEXIT_CRITICAL", 1614)
  </code></pre>
  
  <p>Two elements are removed based on the condition of iterating the list and only picking the previous EXIT upon encountering the next ENTER in the list</p>
  
  <p>Finally need to transform this into a tripe</p>
  
  <pre><code>("CS", 1443, 1528)
  ("CS", 1551, 1555)
  ("CS", 1602, 1614)
  </code></pre>