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

  • Home
  • SEARCH
  • 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 210191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:58:59+00:00 2026-05-11T17:58:59+00:00

I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but

  • 0

I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but I don’t want to make it Ordered[A] just for this one purpose. I don’t consider the ordering I want to use with respect to the PriorityQueue as the natural ordering of the class.

class MyObject (sequence: Int, values: List[String]) ...

So, in my PriorityQueue, I would like the values to be ordered by ‘sequence’. However, just because two objects have the same sequence doesn’t make them naturally equal since the contents of their ‘values’ may be different.

This is where, in Java, it’s nice to be able to supply an alternate Comparator object to the PriorityQueue. My Comparator would simply order the objects with respect to their ‘sequence’ and ignores their ‘values’.

The PriorityQueue class must be parameterized with a “A <% Ordered[A]”

class PriorityQueue[A <% Ordered[A]] extends ... 

From what I’ve read, this means my class must extend Ordered[A] or I must provide an “implicit def” type conversion to Ordered[A], which, honestly, feels inelegant.

The Java solution seems more “functional” allowing me to pass a Comparator function-like object instead of forcing me into a class hierarchy or monkeypatching my class.

I realize there are alternatives to using PrioirityQueue, but I feel like I may be bumping up against the Scala learning curve here and don’t want to give up without exploring this design decision fully.

Is this just an unfortunate decision in the Scala library or am I misunderstanding some sort of calling convention that makes PriorityQueue more usable and ‘functional’?

Thanks

  • 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-11T17:58:59+00:00Added an answer on May 11, 2026 at 5:58 pm

    The syntax

    class PriorityQueue[A <% Ordered[A]] ...
    

    is really just a light sugaring on top of

    class PriorityQueue[A]()(implicit convert: A => Ordered[A]) ...
    

    This means you can write your own method A => Ordered[A]

    case class Foo(n: Int)
    def orderedFoo(f: Foo): Ordered[Foo] = new Ordered[Foo] {
      def compare(other: Foo) = f.n.compare(other.n)
    }
    

    And manually pass it into your PriorityQueue constructor

    new PriorityQueue[Foo]()(orderedFoo)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 213k
  • Answers 213k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Markus Müller's comment is correct, that is, your code is… May 12, 2026 at 10:37 pm
  • Editorial Team
    Editorial Team added an answer Yes - you could use a different serialization format. The… May 12, 2026 at 10:37 pm
  • Editorial Team
    Editorial Team added an answer Are you using Prism? CAL WPF? If so you might… May 12, 2026 at 10:37 pm

Related Questions

I have a class that I have to call one or two methods a
I have a class that I want to use to store properties for another
I have a method in a singleton class that need to use the .NET
I have a performance-intensive iPhone game I would like to add sounds to. There

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.