I have created a list of lists like this and I can sort this easily on size.
@ List(List(2, 2, 3), List(7)).sortBy(_.size)
res71: List[List[Int]] = List(List(7), List(2, 2, 3))
However If I have list which has duplicates and I want to eliminate the duplicates I can do
@ List(List(2, 2, 3), List(3, 2, 2), List(7)).map(_.sorted).toSet.toList
res72: List[List[Int]] = List(List(2, 2, 3), List(7))
You can see the data type of the list above is still List[List[Int]]
Now If I try
@ List(List(2, 2, 3), List(3, 2, 2), List(7)).map(_.sorted).toSet.toList.sortBy(_.size)
cmd73.sc:1: missing parameter type for expanded function ((x$2: <error>) => x$2.size)
val res73 = List(List(2, 2, 3), List(3, 2, 2), List(7)).map(_.sorted).toSet.toList.sortBy(_.size)
^
Compilation Failed
I also tried
@ List(List(2, 2, 3), List(3, 2, 2), List(7)).map(_.sorted).toSet.toList.sortBy(x => x.size)
cmd73.sc:1: missing parameter type
val res73 = List(List(2, 2, 3), List(3, 2, 2), List(7)).map(_.sorted).toSet.toList.sortBy(x => x.size)
^
Compilation Failed
I am a little confused. What is the difference between the List[List[Int]] which I build manually vs List[List[Int]] which comes back from the toList function? why is it that I can call sortBy
on the first one, but I can't call sortBy on the second one?