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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:12:14+00:00 2026-05-29T20:12:14+00:00

Somehow, I can’t seem to correctly implement a SortedMap. Here’s a minimal (non-)working example:

  • 0

Somehow, I can’t seem to correctly implement a SortedMap. Here’s a minimal (non-)working example:

class MyMap[A](t: Map[Long, A]) extends SortedMap[Long, A]  {
  protected val internalMap = TreeMap(t.toArray: _*)

  def -(key: Long) = MyMap(internalMap - key)
  def get(key: Long) = internalMap.get(key)
  def rangeImpl(from: Option[Long], until: Option[Long]) = TreeMap(internalMap.rangeImpl(from, until))
  def iterator = internalMap.iterator
  def ordering = internalMap.ordering
}

But, whatever I pass into the MyMap constructor, calling, for example, its size, always returns 0.


Addendum: I just copy-pasted the code to a new project, and it worked 8-\ Anyway, let me change the question in order to make it useful: is this the correct way to extend SortedMap?

  • 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-29T20:12:15+00:00Added an answer on May 29, 2026 at 8:12 pm

    After adding a couple of missing methods to make it compile, your code worked fine for me:

    class MyMap[A](t: Map[Long, A]) extends SortedMap[Long, A]  {
      protected val internalMap = TreeMap(t.toArray: _*)
      def +[B1 >: A](kv: (Long, B1)) = new MyMap(internalMap + kv)
      def -(key: Long) = new MyMap(internalMap - key)
      def get(key: Long) = internalMap.get(key)
      def rangeImpl(from: Option[Long], until: Option[Long]) = internalMap.rangeImpl(from, until)
      def iterator = internalMap.iterator
      def ordering = internalMap.ordering
    }
    

    From the REPL:

    scala> t
    res5: Map[Long,String] = Map(123 -> abc, 456 -> def)
    
    scala> new MyMap(t)
    res6: MyMap[String] = Map(123 -> abc, 456 -> def)
    
    scala> res6.size
    res7: Int = 2
    

    Am I missing something?

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

Sidebar

Related Questions

I've been working all day and I somehow can't get this probably easy task
I'm busy implementing the wurfl api using PHP, but somehow just can't seem to
Somehow I can't seem to get string replacement within a foreach loop in C#
Somehow I can't figure out how to implement the following relations using Doctrine 2
I had this almost working several hours ago, but I can't seem to get
This sounds like a trivial question but somehow I can't seem to figure it
This sure seems like a simple error to fix. However, I somehow can't figure
So my question is if I can somehow send data to my program and
There must be an easy way to do this, but somehow I can wrap
Can I somehow disable spell-checking on HTML textfields (as seen in e.g. Safari)?

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.