Here are two definitions both achieving the same result:
def sendTrigger(teamId:Long, data:String) {
EngineSync.browserSockets.collect{ case ((i,(u,t)),s) => if(t==teamId) { s.send(data) } }
}
def sendTrigger(teamId:Long, data:String) {
EngineSync.browserSockets.foreach{ case ((i,(u,t)),s) => if(t==teamId) { s.send(data) } }
}
What's happening is I am looping through a list of sockets and filtering them to send data. Being a newbie to Scala, I am concerned about performance when this begins to scale. From what I understand foreach
performance is poor compared to other methods, does anyone know if collect
would fare better or if this is the wrong approach entirely?