groupBy is defined as : def groupBy[K](f: A => K): immutable.Map[K, Repr] = {
So f is a function which takes an A and returns K , K is the current type so in below example is List ?
Using below :
val l : List[(String , String)] = List( ("a" , "line1") , ("b" , "line2") , ("b" , "line3") , ("a" , "line4"))
val gm : Map[String,List[(String, String)]] = l.groupBy(_._1)
I'm attempting to convert to type :
val m : Map[String , List[String]] = Map("a" -> List("line1" , "line4") , "b" -> List("line2" , "line3"))
But instead I receive type : Map[String,List[(String, String)]]
How to amend groupBy(_._1)
to return excepted type ? Why is _._1
a function of type A => K
?