title: Scala, trasform filter/foreach of map into For Comprehension
body: <p>here my code: (Variables to use. Is it possible to create a For Comprehension also here instead of foreach? In this code i search all username into players and put it into playersToLobby)</p>
  <pre><code>      private var players: Seq[GamePlayer] = _
        private var totalVotes: Int = this.numberOfPlayers
        private var playersToLobby: Map[String, Int] = Map.empty
  
        this.players.groupBy(_.username).foreach {
            case(username, _) =&gt; this.playersToLobby = this.playersToLobby + (username -&gt; 0)
        }
  </code></pre>
  <p>Then, in this code, i take inside playerToLobby a player with high votes and reset playerToLobby setting it to map.empty. Then i filter gamePlayer to find all alivePlayer and added the all username of alive players into playersToLobby.</p>
  <pre><code>    val playerToEliminate = playersToLobby.maxBy(_._2)._1
      this.playersToLobby = Map.empty
  
      gamePlayer.filter(p =&gt; p.username != playerToEliminate &amp;&amp; p.isInstanceOf[AlivePlayer]).
        groupBy(_.username).foreach {
        case (username, _) =&gt; this.playersToLobby = this.playersToLobby + (username -&gt; 0)
      }
  </code></pre>
  <p>How can i trasform it into a For Comprehension? I have to trasform this into a for comprehension, please, help me ^^&quot;</p>