title: Scala - From tuple to map
body: <p><em>I hope it is okay if I post solved problems and ask for a more beautiful solution, so that I can see how it is done correctly</em></p>
  
  <p>I wanted a list of all process names mapped with a ProcessID. Something like <code>"notepad.exe" -&gt; 4242</code>
  Ofc there can be multiple instances so it should be something like <code>"notepad.exe" -&gt; List(4242,7171)</code></p>
  
  <p>I have a method which gives me a tuple</p>
  
  <pre><code>private def extractProcess(s: String): (String, Int) = {
      val process = s.split(" ").filterNot(str =&gt; str == "")
      (process(0), process(1).toInt)
  }
  </code></pre>
  
  <p>output would be <code>("Notepad.exe",4242)</code></p>
  
  <p>processList containt the raw string from windows tasklist which looks something like this</p>
  
  <pre><code>svchost.exe                   4464 Services                   0        47.656 K
  </code></pre>
  
  <p>Now I want to create a map with all processes and I have done it like this</p>
  
  <pre><code>val process: Map[String, List[Int]] = Map()
      processList.drop(5).map(s =&gt; {
        val element = extractProcess(s)
        if (process contains element._1) {
          val p = process get element._1
          process(element._1) = p.get ::: List(element._2)
        } else {
          process(element._1) = List(element._2)
        }
      })
  </code></pre>
  
  <p><em>I droped the first 5 elements because they are not needed</em></p>
  
  <p>Now the output would look like this</p>
  
  <pre><code>...
  (tasklist.exe,List(5036))
  (NLClientApp.exe,List(2812))
  (wininit.exe,List(444))
  (SearchFilterHost.exe,List(5476))
  (svchost.exe,List(656, 732, 928, 964, 992, 1036, 1140, 1360, 2168, 4464, 4764, 5048))
  ...
  </code></pre>
  
  <p>Which is what I wanted to do.
  Are there better ways of creating the map?</p>
  
  <p>I always think more imperative than functional, it is hard to think different.</p>