5 ms·
If anyone is able, would you please explain to me these two questions from the quiz? I’m stumped. Why does `toSeq` compile, but not `toIndexedSeq`? Set(1,
by jonshea 15y ago
If anyone is able, would you please explain to me these two questions from the quiz? I’m stumped.
Why does `toSeq` compile, but not `toIndexedSeq`?
Set(1,2,3).toIndexedSeq sortBy (-_)
Set(1,2,3).toSeq sortBy (-_)
Why does `h` compile, but `f` does not?
def add(x: Int, y: Int) = x + y
val f = add(1,_)
val h = add(_,_)
- extempore 15y agotoIndexedSeq takes a type parameter (I'm not sure why - it appears unncessary) which means the result of toIndexedSeq is not known when it is attempting to infer the Ordering. toSeq doesn't take one, it's known to be Seq[Int]. The other looks like some quirk of partial application. It's unlikely there's any fundamental reason, only an implementation imperfection.
- jonshea 15y agoGood to know. Thanks Paul!