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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:52:26+00:00 2026-05-30T09:52:26+00:00

What I am trying to do is to write a custom class extending Map[DateTime,

  • 0

What I am trying to do is to write a custom class extending Map[DateTime, T]. The extended class is to take a Map[DateTime, T] as a constructor argument and call corresponding methods of the supplied map for every method a Map is to implement.

I had no problem writing

def -(key: DateTime) = iv.-(key)
def get(key: DateTime) = iv.get(key)

but I’ve got stuck on

+[B1 :>B](kv: (A, B1)):Map[A, B1]

How am I meant to write it?

Isn’t there a simple reference Map wrapper implementation to start from?

PS: Don’t offer to declare it as type DtMap[T] = Map[DateTime, T] – I am going to have to add my own methods into the class.

UPDATE: So, the result looks like this, to consolidate it so that somebody would be able to use it as a starting point for his Map extension (may the solution have some hidden problems – please let me know):

case class DtValMap[T](iv: Map[DateTime, T]) extends Map[DateTime, T] {
  def -(key: DateTime) = new DtValMap(iv.-(key))
  def get(key: DateTime) = iv.get(key)
  def +[T1 >: T](kv: (DateTime, T1)): DtValMap[T1] = new DtValMap(iv + kv)
  def iterator: Iterator[(DateTime, T)] = iv.iterator
}

UPDATE2: I’ve noticed the typo which was causing the problem now: I had :> (wrong) instead of >:. But I intentionally don’t correct it in the text above as it would make the question make no sense.

  • 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-30T09:52:27+00:00Added an answer on May 30, 2026 at 9:52 am

    If I understand correctly, there is

    class YourMap[T](iv: Map[DateTime, T]) extends Map[DateTime, T] 
    

    Can’t you just do

    def +[T1 >: T](kv: (DateTime, T1)): YourMap[T1] = new YourMap(iv + kv)
    

    I’m not too sure about your def -, If I understand correctly, it returns a Map, not a YourMap. If this is ok, why can’t you do just the same for +?

    In the line of type DtMap[T], have you considered adding the method with pimp my library, rather than with class extension? Collection classes are complex, and so is extending them.

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

Sidebar

Related Questions

I am trying to write operator overload for custom class and don't know how
I'm trying to write a custom Panel class for WPF, by overriding MeasureOverride and
I'm trying to write a custom validation class that validates that an email is
I'm trying to write a custom Javascript MVC3 Helper class foe my project, and
I'm trying to write this custom addition class for very large integers, bigger than
I am trying to write a custom actions class library for my WiX install
I'm trying to write a custom cmp function for a map, a simple one
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
I'm trying to write a custom function that will let me retrieve a cell
I am trying to write a custom tag. I can write attributes; however, I'm

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.