Да, этот код мучительно обязателен.В Scala грубый эквивалент будет (!):
def longest(fileName: String) =
Source.fromFile(fileName).getLines().max(Ordering.fromLessThan[String](_.size < _.size)).size
Думаю, не помешало бы дать какое-то объяснение:
def longest(fileName: String) = Source.
fromFile(fileName). //file contents abstraction
getLines(). //iterator over lines
max( //find the max element in iterated elements
Ordering.fromLessThan[String](_.size < _.size) //however, use custom comparator by line size
).size //max() will return the line, we want the line length
Конечно TMTOWTDI в Scala.