logo      
Custom Search

Re: Maps in scala

Date: December 28, 2006
From: "steve.bendiola" <steve.bendiola@xxxxxxxxx>

In-reply-to: <20061108045711.GD856@xxxxxxxxxxxxxxxx>
References: <001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx>

I was going to update the wiki with the different ways to access/modify maps,
but I don't understand why the last line in this code sample fails:

val map = new scala.collection.mutable.HashMap[String, Any]
            
map("likes") = "cheese"
assume( map.get("likes") == Some("cheese") )
assume( map("likes") == "cheese")
      
assume( map.get("fakeKey") == None)

map += "name" -> "Gromit"
assume( map("name") == "Gromit")

map += "id" -> 1234
assume( map.get("id") == Some(1234) )
assume(map.get("id") == 1234, "map.get(id) == 1234 failed" )


Jamie Webb wrote:
> 
> On Tue, Nov 07, 2006 at 08:58:56PM -0600, John Williams wrote:
>> This is good stuff!  It's perfectly obvious once you see it, but it
>> would have taken me forever to think of this on my own.  Has anyone
>> made a collection of tips like this somewhere?  I think such a
>> collection would be a big help to Scala programmers who are trying to
>> move beyond writing Java-like code.
> 
> The Wiki at scala.sygneca.com has various code examples, but they tend
> to be longer.
> 
> Trouble is, personally I would have trouble identifying 'tips' unless
> I'm asked a question. Maybe someone could start a 'most hated Java
> idioms' page and we'll see how Scala fares...
> 
> -- Jamie Webb
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Maps-in-scala-tf2573926.html#a8071592
Sent from the Scala mailing list archive at Nabble.com.





Custom Search
home | non blog view