Finding the longest word from a list of words
Whenever I only use the extracted value once in a simple group / map / sortBy monadic operations I use the _ placeholders.  I think it makes the code a little more compact and readable, especially if it was just a placeholder value like x

.groupBy(x =&gt; x._1) becomes .groupBy(_._1)

.mapValues(x =&gt; x.toSet) becomes .mapValues(_.toSet) or even mapValues toSet if you like infix

It's not a universal rule by any means, sometimes you really need a meaningful name so that another coder could make sense of it.

Edit
Also you can go straight to the group by and remove redundant counts

val oneLiner = line.groupBy(_.length).mapValues(_.toSet).maxBy(_._1)

//&gt; oneLiner  : (Int, scala.collection.immutable.Set[String]) = (3,Set(abc, pqr, mnp, jkl, xyz))