Reputation: 1155
Lets say val a = List[List[int]]: What is the cleanest way to find the list that contains the most amount of elements in Scala?
Upvotes: 2
Views: 145
Reputation: 27535
Try one of .maxBy
or .maxByOption
List(List(0)).maxBy(_.size) // List(0)
List(List(0)).maxByOption(_.size) // Some(List(0))
List.empty[List[Int]].maxByOption(_.size) // None
Upvotes: 5