का उपयोग कर मुझे आश्चर्य है कि क्यों List(3,2,1).toIndexedSeq.sortBy(x=>x)
काम नहीं करता:स्केला - भ्रामक "अपसारी निहित विस्तार" त्रुटि जब "sortBy"
scala> List(3,2,1).toIndexedSeq.sortBy(x=>x) // Wrong
<console>:8: error: missing parameter type
List(3,2,1).toIndexedSeq.sortBy(x=>x)
^
<console>:8: error: diverging implicit expansion for type scala.math.Ordering[B]
starting with method Tuple9 in object Ordering
List(3,2,1).toIndexedSeq.sortBy(x=>x)
^
scala> Vector(3,2,1).sortBy(x=>x) // OK
res: scala.collection.immutable.Vector[Int] = Vector(1, 2, 3)
scala> Vector(3,2,1).asInstanceOf[IndexedSeq[Int]].sortBy(x=>x) // OK
res: IndexedSeq[Int] = Vector(1, 2, 3)
scala> List(3,2,1).toIndexedSeq.sortBy((x:Int)=>x) // OK
res: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 2, 3)
इसके अलावा, 'सूची (3,2,1) .toIndexedSeq.sortBy (पहचान)' एक और उपयोगी त्रुटि और 'सूची (3,2,1) देता है। toIndexedSeq [Int] .sortBy (x => x) 'ठीक काम करता है। – dhg
नोट, कि आप sortBy और toIndexedSeq स्विच कर सकते हैं: 'सूची (3, 2, 1) .sortBy (x => x)। toIndexedSeq' –