why scala placeholder doesn't work -


hello i'm trying understand symbol "_" in scala, looks wildcard did not understand why in given scenario.

   var l = list("a","b" ,"c")    // works "s" works variable.    l.foreach( s =>      if(s=="a"){        print(s)      }    )     // works _ takes place of "s"    l.foreach(      print(_)    )    //so doubt whether "_" wildcard not work well.    l.foreach(     if(_=="a"){       print(_)     }   ) 

"_" should act variable s, why doesn't?

wildcards in anonymous functions expanded in way n-th _ treated n-th argument. way you're using makes scala compiler think you're have like

l.foreach((x,y) =>     if(x=="a"){       print(y)     } ) 

which invalid.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -