好的,如果我知道該怎麼做,我不會來幫助你,反正,我的「程序」仍然有問題。scala根據對象參數錯誤對列表進行排序
class Mark(val name: String, val style_mark: Double, val other_mark: Double) {}
object Test extends Application
{
val m1 = new Mark("Smith", 18, 16);
val m2 = new Mark("Cole", 14, 7);
val m3 = new Mark("James", 13, 15);
val m4 = new Mark("Jones", 14, 16);
val m5 = new Mark("Richardson", 20, 19);
val m6 = new Mark("James", 4, 18);
val marks = List[Mark](m1, m2, m3, m4, m5, m6);
def avg(xs: List[Double]) = xs.sum/xs.length
val marksGrouped = marks.groupBy(_.name).map { kv => new Mark(kv._1, avg(kv._2.map(_.style_mark)), avg(kv._2.map(_.other_mark))) }
val marksSorted = marksGrouped.sortWith((m1, m2) => m1._style_mark < m2._style_mark)
}
這是我的錯誤:error: value sortWith is not a member of scala.collection.immutable.Iterable[Mark]
他需要調用toSeq ... – 2010-10-23 12:39:00