Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:50:08+00:00 2026-05-31T00:50:08+00:00

I wonder why List(3,2,1).toIndexedSeq.sortBy(x=>x) doesn’t work: scala> List(3,2,1).toIndexedSeq.sortBy(x=>x) // Wrong <console>:8: error: missing parameter

  • 0

I wonder why List(3,2,1).toIndexedSeq.sortBy(x=>x) doesn’t work:

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:50:09+00:00Added an answer on May 31, 2026 at 12:50 am

    If you look at the type signature of toIndexedSeq on List you’ll see it takes a type parameter B, which can be any supertype of A:

    def toIndexedSeq [B >: A] : IndexedSeq[B] 
    

    If you leave out that type parameter then the compiler essentially has to guess what you meant, taking the most specific type possible. You could have meant List(3,2,1).toIndexedSeq[Any], which of course can’t be sorted since there’s no Ordering[Any]. It seems the compiler doesn’t play “guess the type parameter” until the whole expression has been checked for correct typing (maybe someone who knows something about compiler internals can expand on this).

    To make it work you can either a) provide the required type parameter yourself i.e.

    List(3,2,1).toIndexedSeq[Int].sortBy(x=>x)
    

    or b) separate the expression into two so that the type parameter has to be inferred before calling sortBy:

    val lst = List(3,2,1).toIndexedSeq; lst.sortBy(x=>x)
    

    Edit:

    It’s probably because sortBy takes a Function1 argument. The signature of sortBy is

    def sortBy [B] (f: (A) => B)(implicit ord: Ordering[B]): IndexedSeq[A] 
    

    whereas sorted (which you should use instead!) works fine with List(3,2,1).toIndexedSeq.sorted

    def sorted [B >: A] (implicit ord: Ordering[B]): IndexedSeq[A] 
    

    I’m not sure exactly why Function1 causes this problem and I’m going to bed so can’t think about it further…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder why Java compiler doesn't trust in this line of code : List<Car>
I wonder what the time complexity of the pop method of list objects is
I wonder if there is a way to create a Custom List in Sharepoint,
I wonder, if I can inject a list of (stateless) beans, that all implementing
wonder what's wrong <table id=tblDomainVersion> <tr> <td>Version</td> <td>No of sites</td> </tr> <tr> <td class=clsversion>1.25</td>
I wonder how to list the content in an archive file and remove some
I wonder how to list the content of a tar file only down to
I wonder how one can list all methods in a module, but not including
I wonder is it possible to keep list of files or folders opened before
I wonder how I should do to read objects from a list if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.