How do I return a String from a for comprehension in Scala?

Posted by Vonn on Stack Overflow See other posts from Stack Overflow or by Vonn
Published on 2010-06-04T15:16:25Z Indexed on 2010/06/05 17:52 UTC
Read the original article Hit count: 129

Filed under:

Scala Newbie alert:

basically I'm trying to do something like this: where I pattern match and return a String.

scala> def processList(list: List[String], m: String): String={list foreach (x=> m match{
 | case "test" => "we got test"                                                      
 | case "test1"=> "we got test1"})}                                                  

:10: error: type mismatch; found : Unit required: String def processList(list: List[String], m: String): String={list foreach (x=> m match{

I know I can set a var and return it after the for comp... but that doesn't seem to be the Scala way.

© Stack Overflow or respective owner

Related posts about scala