I saw a below code:
Map(1 -> "one", 2 -> "two") map _._1
this return a Iterable[Int], but if I want to do nothing with map, how to do it?
I want to do something like below, but the below code can't compile, I know because it a object instance not a function, but how to create a function to do x => x
and use placeholder:
Map(1 -> "one") map (_) // map (Int, String) to (Int, String) by nothing change
// I test some other way, but all can't compile
how to do this?
UPDATED
Sorry for confuse passionate person. I want to know why map (_) != map (x => x)
, compiler transform this code to (x$1) => Map(1.$minus$greater("one")).map(x$1)
why not Map('a'.$minus$greater(1)).map((x$1) => x$1)
, and does there has a way can use _
make this code?
I used below code to help compiler inferred the _
type:
Map(1 -> "one") map (_:((Int, String))=>(Int, String))
// but it return (((Int, String)) => (Int, String)) => scala.collection.immutable.Map[Int,String] = <function1>
It seem the parser was not sure where to put the beginning of the anonymous function. So my new question is "How to help the parser to restrict a anonymous function's boundary?"