The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Noob: Using -> Operator with Map factory method

2 replies on 1 page. Most recent reply: Oct 23, 2008 10:02 PM by Vladimir Kelman

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Bhaskar Maddala

Posts: 5
Nickname: maddalab
Registered: Feb, 2006

Noob: Using -> Operator with Map factory method Posted: Oct 15, 2008 10:33 AM
Reply to this message Reply
Advertisement
I was reading chapter 3 of Programming in Scala Step 11 and noticed the use of -> operator when initializing immutable Map. The operator was used to create a tuple to pass to the factory method of Map.


val romanNumeral = Map(1 -> "I", 2 -> "II", 3 -> "III", 4 -> "IV", 5 -> "V")


When should I use the -> operator since I could accomplish the same using


val romanNumeral = Map((1,"I"),(2,"II"),(3,"III"),(4,"IV"),(5,"V"))


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Noob: Using -> Operator with Map factory method Posted: Oct 15, 2008 2:37 PM
Reply to this message Reply
I would pretty much always use the -> when making maps, because it is idiomatic, and therefore probably more recognizable/readable than just plain old tuples.

Vladimir Kelman

Posts: 46
Nickname: vkelman
Registered: Feb, 2008

Re: Noob: Using -> Operator with Map factory method Posted: Oct 23, 2008 10:02 PM
Reply to this message Reply
But functionally both ways are equivalent, right? Operator "->" creates a tuple as well...

Flat View: This topic has 2 replies on 1 page
Topic: Problems with Element examples Previous Topic   Next Topic Topic: Spreadsheet example: changes already propagated

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use