を使用しているとき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)
また、 'List(3,2,1).toIndexedSeq.sortBy(identity)'はより有用なエラーと 'List(3,2,1)。 toIndexedSeq [Int] .sortBy(x => x) 'はうまく動作します。 – dhg
sortByとtoIndexedSeq: 'List(3、2、1).sortBy(x => x)を切り替えることができます。 toIndexedSeq' –