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 6626479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:53:50+00:00 2026-05-25T21:53:50+00:00

Given: case class Person(name: String) and trying to do: scala> List(Person(Tom), Person(Bob)).sorted results in

  • 0

Given:

case class Person(name: String)

and trying to do:

scala> List(Person("Tom"), Person("Bob")).sorted

results in a complaint about missing Ordering.

<console>:8: error: could not find implicit value for parameter ord: Ordering[Person]
   List(Person("Tom"), Person("Bob")).sorted

However this:

case class Person(name: String) extends Ordered[Person] {
  def compare(that: Person) = this.name compare that.name }

works fine as expected:

scala> List(Person("Tom"), Person("Bob")).sorted
res12: List[Person] = List(Person(Bob), Person(Tom))

although there’s no Ordering or implicits involved.

Question #1: what’s going on here? (My money is on something implicit…)

However, given the above and the fact that this:

scala> Person("Tom") > Person("Bob")
res15: Boolean = true

works, and that also this:

scala> List(Some(2), None, Some(1)).sorted

works out of the box:

res13: List[Option[Int]] = List(None, Some(1), Some(2))

I would expect that this:

scala> Some(2) > Some(1)

would also work, however it does not:

<console>:6: error: value > is not a member of Some[Int]
       Some(2) > Some(1)

Question #2: why not, and how can I get it to work?

  • 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-25T21:53:50+00:00Added an answer on May 25, 2026 at 9:53 pm

    Concerning your first question: Ordered[T] extends Comparable[T]. The Ordering companion object provides an implicit Ordering[T] for any value that can be converted into a Comparable[T]:

    implicit def ordered[A <% Comparable[A]]: Ordering[A]
    

    There is no implicit conversion A : Ordering => Ordered[A] – that’s why Some(1) > Some(2) will not work.

    It is questionable if it is a good idea to define such a conversion as you may end up wrapping your objects into Ordered instances and then create an Ordering of that again (and so on…). Even worse: you could create two Ordered instances with different Ordering instances in scope which is of course not what you want.

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

Sidebar

Related Questions

Given: case class Person(name:String = Bob, age:Int = 20) How can I accept the
Given, case class User(name: String, roles: List[String]) val users: List[User] = ... I'd like
Given: case class FirstCC { def name: String = ... // something that will
Given the following code: case class ChangeSet(field:String, from:Object, to:Object) private var changed:List[ChangeSet] = Nil
Given a model: class Person validates_lenght_of :name, :maximum => 50 end I have some
Given: case class Foo(a: Int, b: String, c: Double) you can say: val params
In Scala, I am grabbing the type of a given class through its Scala
Given the following case: <?php class ParentClass { public $attrA; public $attrB; public $attrC;
Given this example: abstract class Base { type Value } case object Foo extends
My use case is that a List<String> is passed to a Jpanel and for

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.