Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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(_,_)


toIndexedSeq 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.


Good to know. Thanks Paul!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: