scala - Why "value.foreach(setValue(_.toInt))" can't be compiled -


scala code:

val value = some("100") value.foreach( println(_.toint) )   // !!! can't compiled 

the error message is:

missing parameter type expanded function ((x$1)=>x$1.toint)

why can't compiled?

ps: , following code valid:

value.foreach( _.toint ) value.foreach( x => println(x.toint) ) 

the compiler message bit misleading, provides hint: tells interpreted _.toint (x$1)=>x$1.toint. so, putting in place, get

value.foreach( println( (x$1)=>x$1.toint ) ) 

which not intended.

here's imo cleanest way solve issue:

value.map( _.toint ).foreach( println ) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -