This page is no longer maintained — Please continue to the home page at www.scala-lang.org

withDefault and withDefaultValue for mutable maps

2 replies
huynhjl
Joined: 2009-10-27,
User offline. Last seen 42 years 45 weeks ago.

This is a follow up to this stackoverflow question
http://stackoverflow.com/questions/3648870/scala-using-hashmap-with-a-de....

This works with immutable maps: Map(1 -> "b", 2 ->
"a").withDefaultValue("-").

It seems this would be practical with mutable maps as well. There is also a
comment in
http://www.scala-lang.org/api/current/scala/collection/immutable/Map.html
that suggests that withDefault could move to general map.

Should I submit a enhancement request ticket? I was not able to find
anything with Map and withDefault keywords.

--huynhjl

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: withDefault and withDefaultValue for mutable maps

On Tue, Sep 7, 2010 at 12:31 AM, huynhjl wrote:
>
> This is a follow up to this stackoverflow question
> http://stackoverflow.com/questions/3648870/scala-using-hashmap-with-a-de....
>
> This works with immutable maps: Map(1 -> "b", 2 ->
> "a").withDefaultValue("-").
>
> It seems this would be practical with mutable maps as well. There is also a
> comment in
> http://www.scala-lang.org/api/current/scala/collection/immutable/Map.html
> that suggests that withDefault could move to general map.
>
Yes, please do!

huynhjl
Joined: 2009-10-27,
User offline. Last seen 42 years 45 weeks ago.
Re: withDefault and withDefaultValue for mutable maps

Martin Odersky wrote:
>
> On Tue, Sep 7, 2010 at 12:31 AM, huynhjl wrote:
>>
>> This is a follow up to this stackoverflow question
>> http://stackoverflow.com/questions/3648870/scala-using-hashmap-with-a-de....
>>
>> This works with immutable maps: Map(1 -> "b", 2 ->
>> "a").withDefaultValue("-").
>>
>> It seems this would be practical with mutable maps as well. There is also
>> a
>> comment in
>> http://www.scala-lang.org/api/current/scala/collection/immutable/Map.html
>> that suggests that withDefault could move to general map.
>>
> Yes, please do!
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland