Scala中->と

922 ワード

for ,for (i
scala> val n = 5
n: Int = 5

scala> for (i 

->の
『Scala for the Impatient』の で する
In Scala, a map is a collection of pairs. A pair is simply a grouping of two values, not necessarily of the same type, such as("Alice", 10). The -> operator makes a pair. The value of "Alice"-> 10 is ("Alice", 10)
したがって、 に->はmap のkey/value pairsを するために され、 えば
scala> val scores = Map("Alice" -> 10, "Bob" ->3, "Cindy" -> 8)
scores: scala.collection.immutable.Map[String,Int] = Map(Alice -> 10, Bob -> 3, Cindy -> 8)

scala> val newSources = scores + ("Bob" -> 10, "Fred" -> 7)
newSources: scala.collection.immutable.Map[String,Int] = Map(Alice -> 10, Bob -> 10, Cindy -> 8, Fred -> 7)